I hope somebody could help me out in my problem with the recruitment application I am working on.
Background:
1. User selects an applicant from the gridview, and clicks the image button on the row corresponding to the applicant.
2. On the backend, web application creates a PDF using a template with the help of iTextSharp, then saves the file to a virtual directory (D:/).
3. Afterwards, the user should be able to download that PDF using a save dialog of some sort.
But I get exceptions like something related to Microsoft JScript and something like "Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack." while debugging.
Please help me out on this. I'm really having a hard time with the code snippet pertaining to Response.Write(), Response.Flush() Response.End(), etc.
Hi... if ur transmitting a file to client as download untill server sending total data to client the process will takes place so u shouldn't call Response.End()... if u calls this method server will throw this error because the file transfer is in progress
but ur calling Response.End() method...
I've solved this problem of mine. Thanks to your contributions as well.
The background of the problem that I forgot to indicate here was I was triggering a download event from a click to an image button in a gridview row of a gridview inside a Ajax Control Toolkit tab container.
Out of frustration, I just tried declaring the tab container as a post back trigger in the triggers of the update panel, and voila, the save as dialog appeared in the browser. And by the way, thanks to
chikkanti, I used his code snippet!
Thanks,
Marked as answer by kenchi09 on Dec 12, 2012 01:59 AM
kenchi09
Member
2 Points
5 Posts
Web Application File Downloading Problem
Dec 08, 2012 08:07 AM|LINK
Hi Everyone,
I hope somebody could help me out in my problem with the recruitment application I am working on.
Background:
1. User selects an applicant from the gridview, and clicks the image button on the row corresponding to the applicant.
2. On the backend, web application creates a PDF using a template with the help of iTextSharp, then saves the file to a virtual directory (D:/).
3. Afterwards, the user should be able to download that PDF using a save dialog of some sort.
But I get exceptions like something related to Microsoft JScript and something like "Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack." while debugging.
Please help me out on this. I'm really having a hard time with the code snippet pertaining to Response.Write(), Response.Flush() Response.End(), etc.
chikkanti
Member
270 Points
80 Posts
Re: Web Application File Downloading Problem
Dec 08, 2012 10:04 AM|LINK
Hi... if ur transmitting a file to client as download untill server sending total data to client the process will takes place so u shouldn't call Response.End()... if u calls this method server will throw this error because the file transfer is in progress but ur calling Response.End() method...
User the following code...
string DownloadedPath = AppDomain.CurrentDomain.BaseDirectory + "\\" + gItem.Cells[9].Text.ToString(); FileInfo fi = new FileInfo(DownloadedPath); long sz = fi.Length; Response.ClearContent(); Response.ContentType = MimeType(Path.GetExtension(Path.GetExtension(DownloadedPath))); Response.AddHeader("Content-Disposition", "attachment; filename=\"" + System.IO.Path.GetFileName(DownloadedPath) + "\""); Response.AddHeader("Content-Length", sz.ToString("F0")); Response.TransmitFile(DownloadedPath); Response.Flush(); //Response.End();we can user Response.Flush() method to send buffered data to client...
after completion of all ur work call ur
kenchi09
Member
2 Points
5 Posts
Re: Web Application File Downloading Problem
Dec 08, 2012 11:36 AM|LINK
Hi chikkanti,
I still get this kind of error when i used your code snippet:
Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed.
Thanks,
kenchi09
Member
2 Points
5 Posts
Re: Web Application File Downloading Problem
Dec 12, 2012 01:58 AM|LINK
Hi Everyone,
I've solved this problem of mine. Thanks to your contributions as well.
The background of the problem that I forgot to indicate here was I was triggering a download event from a click to an image button in a gridview row of a gridview inside a Ajax Control Toolkit tab container.
Out of frustration, I just tried declaring the tab container as a post back trigger in the triggers of the update panel, and voila, the save as dialog appeared in the browser. And by the way, thanks to chikkanti, I used his code snippet!
Thanks,