Big Files and Downlaod using asp.net

L

Liensun

The application is coded using ASP.net and C#.
A part of the application allows the user to download files. The size of
these files can be up to 80 MB.

It works when the connection bandwidth is high. But in other cases, after a
few minutes, the next message is displayed: "The connection with
server was reset".

Here the code that I use:
private void SendPageToBrowser(string filename)

{
// All mime type supports
StringDictionary MimeTypeList = new StringDictionary();
MimeTypeList[".doc"] = "application/ms-word";
MimeTypeList[".zip"] = "application/zip";
MimeTypeList["*"] = "application/octet-stream";

FileInfo fi = new FileInfo(Server.MapPath(filename));
// Checks also that the file exists before cleaning the response
// in case, it doesn't exist, an exception is raised
string FileLength = fi.Length.ToString();
Response.BufferOutput=true;
Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.ContentType = MimeTypeList[fi.Extension];
if (Response.ContentType == null)
{
Response.ContentType = MimeTypeList["*"];
}
Response.AppendHeader("Content-Disposition","attachment;filename=" +
fi.Name);
Response.AppendHeader("Content-Length", FileLength);
if (fi.Length < LOWER_LIMIT)
{
Response.WriteFile(fi.FullName );
}
else
{
Byte[] Buffer = new Byte[CHUNKSIZE];
FileStream DLFile = fi.OpenRead();
while ((Response.IsClientConnected)
&& (DLFile.Read(Buffer,0,CHUNKSIZE) != 0)
)
{

Response.BinaryWrite(Buffer);
Response.Flush();
}
DLFile.Close();
}
Response.End();
}

What's wrong in my code or which settings of IIS I have to change?

Any helps will be greatly appreciated.

Olivier.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top