I am providing a PDF file to the user in an ASP.NET application. I have included the code I am using the do this. This works great if that’s the only thing I’m doing on that request. What I would really like to do is show provide this PDF file on Form Load without affecting any of the other stuff in the Form Load event. Can somebody point out what I’m doing wrong in the code? Thanks!!
Response.Clear();
Response.Buffer = true;
Response.ContentType = file.ContentType;
Response.AddHeader("content-disposition", String.Format("attachment; filename=\"{0}\"", file.OriginalFileName));
Response.TransmitFile(Path.Combine("C:\", file.FileName));
Response.End();
As mentioned above, I’d probably use a separate page, and also don’t use the standard asp.net pipeline, consider using a custom httphandler for pdf’s instead, also Phil Haack has a great template to get you started.