views:

523

answers:

2

Hi all,

The following code is implemented in Page_Load event to show SaveFileDialog to the user

string targetFileName = Request.PhysicalApplicationPath + "Reports\\TempReports\\FolderMasters" + Utility.GetRandomNumber() + ".pdf";

FileInfo file = new FileInfo(targetFileName);
// Clear the content of the response.
Response.ClearContent();

Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/pdf";
Response.TransmitFile(file.FullName);
Response.End();

How can I get the user response to SaveFileDialog, as I need to know user response to this dialog?

Also, is there something wrong with these lines of code, as I had the following exception

"Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack."

A: 

Hi, I'm here again, as I got a solution for my second question.

For Response.End, call the HttpContext.Current.ApplicationInstance.CompleteRequest method instead of Response.End to bypass the code execution to the Application_EndRequest event.

Have look ...

Ahmed
+1  A: 

You can't get the user response to SaveFileDialog as all file-events have been blocked for browser-javascript as it could be a very big security-hole ...

roenving