Asked by:
Force download box

Question
-
User-343881177 posted
Hello there, can anyone help me with my proble. The code below run perfectly. The only thing is that after the Sub DownloadFile (FilePath as String) is run the whole webpage seem to stop. The message "Download Completed!" never show at all. When I try to click on other links, it doesn't work as well. It only work when I click the refresh button. Any ideas why? Sub Download (s As Object, e As ImageClickEventArgs) DownloadFile (MapPath(FileUrl)) lblDownload.Text = "Download completed!" End Sub Sub DownloadFile(FilePath as String) If File.Exists(FilePath) Then Dim myFileInfo as FileInfo myFileInfo = New FileInfo(FilePath) Response.Clear() Response.ContentType = "application/octet-stream" Response.AppendHeader("Content-Disposition", "attachment; filename=""" & _ myFileInfo.Name & """") Response.WriteFile(FilePath) Response.End() End If End Sub Thaning you in advance for your help. ChanMonday, December 16, 2002 7:45 AM
All replies
-
User-109060882 posted
I would imagine that once you call Response.End(), the response is over. You can't change anything in the web form because you're not updating the web form at all. When the user hits your Download button on the page, you're not doing a normal postback in the sense that you're ignoring all the standard ASP.NET stuff that happens, and instead just stuffing a file down to the user.Monday, December 16, 2002 6:12 PM -
User-327760478 posted
I have also a problem like this. After download operation, the links on the page does not work. After refresh, they run properly. I haven't done Response.End() but the problem still exists. Is there anyone who can help me? Thanks you in advance. MelTuesday, December 17, 2002 8:02 AM -
User1793549600 posted
I am also having the same problem after downloading file. If any of you fixed it, please post the same. Thanks in Advance, Subramanyam.Thursday, December 19, 2002 4:57 AM -
User-2117473814 posted
Hi, Anyone managed to fix this bug.....?? If so, please let us know what needs to be done.Friday, January 31, 2003 3:06 AM -
User736975731 posted
Are you doing the following (?): a postback to the server (submit the form) by pressing for instance a download button and then reply with writing back an octet stream and ending the response? Just of the top of my head here, but I would think your browser would still think the form submittal is being processed on the server, right?Friday, January 31, 2003 1:52 PM -
User736975731 posted
If I read Eilon's response a little more carefully, I think he is saying the same thing: the download file message will never be displayed, because you ended the response and that ends the processing: the client side will never get any other response to the postback (submittal of the form) than an octet stream. In other words: I don't think it's a good idea to write binary content to the browser during a postback and then ending the response.Friday, January 31, 2003 1:59 PM -
User-1920629146 posted
It's only my idea. redirect to download page ex. download.aspx and use this construction: Response.BufferOutput = False Response.Clear() Response.AppendHeader("Connection", "close") Response.ContentType = "binary/octet" ' save file Response.WriteFile(path) PeterTuesday, February 4, 2003 5:05 AM -
User1751016021 posted
I have a similar problem that I posted on the web forms forum ------> ___________________________________________________ I have a web application which uses a 4 frame design for content management. Essentially, there is the left frame which provides "menu" options or navigation, a header frame, a footer frame, and the content frame in the middle. So, when a user select a menu option, the associated page is loaded in the content frame. Standard stuff. Here's my problem. I have a particular page which allows the user to generate a file on the server for download to the client via the browser. This page in turn sends the file name via query string to a page that handles downloading of file generically. I am using the following standard code (C#) for this: ////////////////////////////////////////////////////////////////////////////////// string strPath = Request.QueryString["downloadFile"].ToString(); string strName = Path.GetFileName(strPath); FileInfo fiDownload = new FileInfo(strPath); if ((fiDownload != null) && (fiDownload.Exists == true)) { Response.BufferOutput = true; Response.ContentType = "text/xml"; // forcing the type currently Response.AddHeader("Content-Disposition", "attachment;filename=" + strName); Response.WriteFile(fiDownload.FullName); Response.End(); } ///////////////////////////////////////////////////////////////////////////////// This code works great. The download dialog pops up with the name of the file displayed. The user can then download to a local directory. All great. However, upon completion of the save, let's say the user wants to now select another menu option from the navigation frame on the left. At this point, regardless of the option selected, the new page will not load into the content frame. I have traced this through debugging to note that through the Application_EndRequest event the content of the page seems to be that of the selected menu option (page). However, the page that invoked the download is still displayed in the content frame. The new page never gets written to the browser. Any ideas as to what is going on here? ThanksFriday, February 21, 2003 3:12 PM -
User1384996337 posted
Hi, I have same problem with the frames, I found that the attachment value in the header "Content-Disposition" is the problem, but is necesary for download. If I write another value, for example "in-inline" or "unspecified" the content of the file is displayed on the frame. Any idea for this?Friday, March 21, 2003 5:40 AM -
User-1069184416 posted
Please try this <post>833372</post> regardsSunday, February 20, 2005 6:01 AM -
User-914589562 posted
Hi, I am guessing that your download control does not stream files to the client. I tried your download component with a 200 MB file and memory usage went up by far more than 400 MB, almost bringing my machine to a complete halt. Kind regards, Mike.Friday, March 4, 2005 9:29 AM -
User-1069184416 posted
Well I haven't tried it with large files, but I did nothing but using the normal way of downloading all files. So the problem might not be in my code, because it is a code used widely to download files. regardsFriday, March 4, 2005 10:12 AM -
User-914589562 posted
OK. That's cool. The only thing that I would say is that if you are using Response.WriteFile, you might be better using Response.OutputStream.Write. This is certainly the case when you are downloading large files. For more information, see http://support.microsoft.com/kb/812406/EN-US/ Cheers!Friday, March 4, 2005 11:21 AM -
User-914589562 posted
But going back to Chanloongloo's first comment. Has anyone solved this problem? Because I have done quite a few Google searches and it seems that many people are having the same problem. The problem is actually driving me mad!! I have written an HttpHandler that is used to download files. In the ProcessRequest function, I open a file, and then in a while loop stream the file to the HttpResponse ouput stream. I continue until the whole file is streamed to the client or the HttpResponse method IsClientConnected returns false. If a big file is downloaded and the user chooses Open in the resulting IE File Download box, everything is OK - If the user hits cancel during the download, IsClientConnected goes false and the code exits. However, if the user chooses Save in the IE File Download box and then cancels half way through, IsClientConnected does not go false - it remains true and the aspnet process locks up, meaning that subsequent page requests fail. I have Googled and I can see many other people have had this problem, but I just haven't got a clue how to fix it. Pleeeeeease can anyone help!? This is driving me nuts. Thanks! The code in ProcessRequest looks something like this....System.Web.HttpResponse httpResponse = context.Response; httpResponse.ContentType = "application/octet-stream"; httpResponse.AddHeader("Content-Disposition", "attachment; filename=\"image1.bmp\""); System.IO.Stream stream = new System.IO.FileStream( @"C:\Home\downloads\image1.bmp", System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read); long bytesToRead = stream.Length; httpResponse.AddHeader("Content-Length", bytesToRead.ToString()); while (bytesToRead > 0) { if (httpResponse.IsClientConnected) { // Just so we get opportunity to hit cancel button on download screen System.Threading.Thread.Sleep(1); // Read the data into the buffer and write into the output stream long toRead = Math.Min(8192, bytesToRead); byte[] buffer = new Byte[toRead]; int length = stream.Read(buffer, 0, (int)toRead); httpResponse.OutputStream.Write(buffer, 0, length); httpResponse.Flush(); // Continue reading remaining bytes bytesToRead = bytesToRead - length; } else { // We might get here if the user hit cancel on their download file popup window bytesToRead = -1; } } finally { stream.Close(); httpResponse.End(); }
Friday, March 4, 2005 12:03 PM -
User-343691196 posted
Thanks for the link. I was having this problem in my application when downloading large files!Friday, March 11, 2005 11:19 AM -
User785325166 posted
Hi
I am facing the same problem while using frames or iframes. It does not work when try to force download in frames, otherwise it works well.
please advise if some one has solved this problem.
Regards.
Wednesday, August 24, 2005 3:25 AM -
User-816038382 posted
Any solution to this? Page is just dead after the download/cancel of the dialoge
Wednesday, October 15, 2008 5:47 PM -
User648825292 posted
Serving files dynamically can be a tricky business. Programs like Adobe Reader inline are especially troublesome as Adobe Reader in "Allow fast web view" mode starts downloading a pdf and soon as it has enough bytes to display the first page it aborts the connection to the web server, and displays the first page. Then it makes a "multipart/byteranges" request to retrieve the rest of the document. This is what causes most download scripts to fail when serving pdf content.
You also don't want to kill your bandwidth by not setting the correct client side caching headers. You don't want the web server memory to fill up with file content to be delivered, so set outputbuffer to false and serve the file in chunks.
You should implement the following headers:
- Accept-Ranges
- Range
- If-Range
- ETag
- Expires
- Last-Modified
- If-Match
- If-None-Match
- If-Modified-Since
- If-Unmodified-Since
- Unless-Modified-Since
For an example implementation checkout:
Monday, March 22, 2010 6:42 AM -
User-624615822 posted
Can anyone please give the soln , since the page is dead after download window is shown.
The user is not able to do anything of the page..unless a refresh happens.
Thursday, May 13, 2010 7:02 AM