Reputation: 5343
i am using the following code to open the pdf byte[] file without saving it. It is working fine but after this action no other server side actions like button click are not working. Postback is not working.
byte[] bytfile = Objects.GetFile(Convert.ToInt32(txtslno.Text.Trim()));
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "attachment;filename="+filename);
Response.AddHeader("Content-Length", bytfile.Length.ToString());
Response.OutputStream.Write(bytfile, 0, bytfile.Length);
Response.Flush();
Response.End();
Upvotes: 1
Views: 3129
Reputation: 19375
It is working fine but after this action no other server side actions like button click are not working.
Are you using your code inside a page or a control?
Use a generic handler (*.ashx) for your purpose. The code for downloading the pdf won't cause troubles for the application anymore.
https://stackoverflow.com/a/12340735/225808 might be useful as a reference.
Upvotes: 0
Reputation: 973
Try this. It shoulld work.
byte[] bytfile = Objects.GetFile(Convert.ToInt32(txtslno.Text.Trim()));
Response.Clear();
MemoryStream ms = new MemoryStream(bytfile);
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=test.pdf");
Response.Buffer = true;
ms.WriteTo(Response.OutputStream);
Response.End();
else try
Response.BinaryWrite(bytfile);
instead of
ms.WriteTo(Response.OutputStream);
in above code.
Upvotes: 4