开发者

Displaying PDF file in ASP.NET without stopping the request

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 stuf开发者_开发知识库f 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.


Response.End() will throw an ThreadAbortException and nothing else will execute. Literally that ends page output.

I recommend you to create another page to generate your PDF file; if you need to send parameters, you could to send them through querystring.


You'll want a separate page for the PDF download.

You can just call the PDF generation page after the form submits (with javascript, a meta refresh, iframe, etc). The effect will be that the form posts, and does whatever, then the PDF download box will appear.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜