Link to home
Start Free TrialLog in
Avatar of LubomirMasar
LubomirMasar

asked on

File Download ends incomplete..500 points..

I have a ASP .NET web page which downloads files..It is working perfectly for small & average sized files..But when I download a large file  (17MB file for instance) it starts the download well, but after 2 minutes or so (after downloading about 6MB) it just finishes. The downloaded file is incomplete. Why is this happening and how can I troubleshoot this?

My download code is given below.
                 FileInfo file = null;
                string filename = null;

                // get the fully qualified name of the selected file
                filename = utils.Utils.GetDownloadsArea() + m_filename;

                // get the file data since the length is required for the download
                file = new FileInfo(filename);

                // write it to the browser
                Response.Clear();
                Response.AddHeader("Content-Disposition",
                    "attachment; filename=" + file.Name);
                Response.AddHeader("Content-Length",
                    file.Length.ToString());
                Response.ContentType = "application/octet-stream";
                Response.WriteFile(filename);
                Response.End();

Anything wrong or suspicious about this code snippet? What other reasons could cause a file download problem?

Thanks..
Avatar of Göran Andersson
Göran Andersson
Flag of Sweden image

That code is not downloading anything. It's sending a file as response, it's the browser that's doing the downloading.

It's probably the request time-out that stops the code. Try to increase the time-out value:

Server.ScriptTimeout = 600; // ten minutes
Avatar of LubomirMasar
LubomirMasar

ASKER

GreenGhost,

That is unlikely..I have set the ASPScriptTimeout of the site at a high value (like 54000 seconds) from the IIS admin tool. Is the Server.ScriptTimeout a different property than that? The website ConnectionTimeout is also high at 1800 secs.
ASKER CERTIFIED SOLUTION
Avatar of Göran Andersson
Göran Andersson
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
In any case, I put the Server.ScriptTimeout = 54000 in code prior to download..Made no difference whatsoever..The download is ending exactly after 90 secs. I dont know why it is so.
90 seconds is the default value for the timeout, which suggests that your attemt to change it failed.

Instead of a timeout of 15 hours, try a more reasonable value, like 15 minutes.

Check if there is a setting for executionTimeout attribute in the httpRuntime element in web.config.