Making any file downloadable from IIS

private void Page_Load(object sender, System.EventArgs e)
{
  
string path = Server.MapPath(Request.Params["File"]);

   System.IO.FileInfo file = new System.IO.FileInfo(path);

   //clear the current output content from the buffer
  
Response.Clear();

   //add the header that specifies filename for the download/saveas dialog
   Response.AddHeader("Content-Disposition","attachment; filename=" + file.Name);

   //add header that specifies size so the browser will show a progress bar
  
Response.AddHeader("Content-Length", file.Length.ToString());

   //Set contenttype so client knows to only download file
  
Response.ContentType="application/octet-stream";

   //send the file
  
Response.WriteFile(file.FullName);

   Response.End();
}

Print | posted on Saturday, July 10, 2004 11:25 AM

Feedback

# re: Making any file downloadable from IIS

left by Majid Malik at 9/12/2005 6:26 PM Gravatar
How do you download a very large file with above method?

With very large file > 100 MB, it takes forever for the browser to get the data and at the end it asks you to save/open the attachment.

But if you add the header statically to the file in iis, the file downloads in pieces and browser asks to save/open the attachment before download starts.


# re: Making any file downloadable from IIS

left by Majid Malik at 9/12/2005 6:28 PM Gravatar
How do you download a very large file with above method?

With very large file > 100 MB, it takes forever for the browser to get the data and at the end it asks you to save/open the attachment.

But if you add the header statically to the file in iis, the file downloads in pieces and browser asks to save/open the attachment before download starts.

Thanks


My email adderess
muh2m@hotmail.com
Title  
Name
Email (never displayed)
Url
Comments   
Please add 5 and 7 and type the answer here: