Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 80619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:19:52+00:00 2026-05-10T21:19:52+00:00

I have an asp.net website that allows the user to download largish files –

  • 0

I have an asp.net website that allows the user to download largish files – 30mb to about 60mb. Sometimes the download works fine but often it fails at some varying point before the download finishes with the message saying that the connection with the server was reset.

Originally I was simply using Server.TransmitFile but after reading up a bit I am now using the code posted below. I am also setting the Server.ScriptTimeout value to 3600 in the Page_Init event.

private void DownloadFile(string fname, bool forceDownload)         {             string path = MapPath(fname);             string name = Path.GetFileName(path);             string ext = Path.GetExtension(path);             string type = '';              // set known types based on file extension                if (ext != null)             {                 switch (ext.ToLower())                 {                     case '.mp3':                         type = 'audio/mpeg';                         break;                      case '.htm':                     case '.html':                         type = 'text/HTML';                         break;                      case '.txt':                         type = 'text/plain';                         break;                      case '.doc':                     case '.rtf':                         type = 'Application/msword';                         break;                 }             }              if (forceDownload)             {                 Response.AppendHeader('content-disposition',                     'attachment; filename=' + name.Replace(' ', '_'));             }              if (type != '')             {                 Response.ContentType = type;             }             else             {                 Response.ContentType = 'application/x-msdownload';             }              System.IO.Stream iStream = null;              // Buffer to read 10K bytes in chunk:             byte[] buffer = new Byte[10000];              // Length of the file:             int length;              // Total bytes to read:             long dataToRead;              try             {                 // Open the file.                 iStream = new System.IO.FileStream(path, System.IO.FileMode.Open,                             System.IO.FileAccess.Read, System.IO.FileShare.Read);                   // Total bytes to read:                 dataToRead = iStream.Length;                  //Response.ContentType = 'application/octet-stream';                 //Response.AddHeader('Content-Disposition', 'attachment; filename=' + filename);                  // Read the bytes.                 while (dataToRead > 0)                 {                     // Verify that the client is connected.                     if (Response.IsClientConnected)                     {                         // Read the data in buffer.                         length = iStream.Read(buffer, 0, 10000);                          // Write the data to the current output stream.                         Response.OutputStream.Write(buffer, 0, length);                          // Flush the data to the HTML output.                         Response.Flush();                          buffer = new Byte[10000];                         dataToRead = dataToRead - length;                     }                     else                     {                         //prevent infinite loop if user disconnects                         dataToRead = -1;                     }                 }             }             catch (Exception ex)             {                 // Trap the error, if any.                 Response.Write('Error : ' + ex.Message);             }             finally             {                 if (iStream != null)                 {                     //Close the file.                     iStream.Close();                 }                 Response.Close();             }          } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T21:19:52+00:00Added an answer on May 10, 2026 at 9:19 pm

    The final fix for this problem was to make a modification in the web.config file. I simply had to change sessionState mode=’InProc’ to sessionState mode=’StateServer’.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Related Questions

Loading...

Sidebar

Ask A Question

Stats

  • Questions 55k
  • Answers 55k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer <jsp:scriptlet> List&lt;String> myText = new List&lt;String>(); </jsp:scriptlet> I tried adding… May 11, 2026 at 7:36 am
  • added an answer If you use MS Ent Lib and their logger you… May 11, 2026 at 7:36 am
  • added an answer There's no language-defined meaning - it's just a convention some… May 11, 2026 at 7:36 am

Top Members

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.