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.’
I’m here again, as I got a solution for my second question.
For
Response.End, call theHttpContext.Current.ApplicationInstance.CompleteRequestmethod instead of Response.End to bypass the code execution to the Application_EndRequest event.Have look …