Home | Articles|Namespace|Interview Questions|Tools|Jobs|Projects|Community
Asp.net Tutorials

»Dotnet Ads
»Message Boards
Message Boards
Dotnet Books

»Member Details
Register
Login
LogOut
Submit Code
Submit Jobs
Submit Projects

»Competition
Community
Winners
Prizes
Write For Us
Members

»Other Resources
Links
Dotnet Resources

File Download and Forcing the File download Dialog in ASP.net

This code will show you how to do file download the code is self explanatory

private void DownloadFile()
{
///get the file
string filepath = Server.MapPath("test.zip");
///get the file stream to get the file length
System.IO.FileStream fs = new System.IO.FileStream(filepath,System.IO.FileMode.Open);
///set the content type
Response.ContentType="application/zip";
///set Content-Disposition
Response.AppendHeader("Content-Disposition","attachment; filename=test.zip");
///get the file size
long filesize = fs.Length;
fs.Close();
///set the content length to the size of the file
///this will chop off the extra junk that may be sent by the ASP.NET runtime along with your file
Response.AddHeader ("Content-Length", filesize.ToString());
///write the file to the browser
Response.WriteFile(filepath);
///flush it
Response.Flush();

}

Have a Question and dont know the answer post it below and get answers in minutes

Due to spam this feature is disabled
To get answers fast , make sure you enter a detailed subject for example: "DataGrid issues need answer" not "DataGrid"

Subject:

Catjegory Name:

Message:



© 2008 dotnetwatch.com -- Privacy policy