Pages

Monday, May 20, 2013

How to download a file from Web Server using ASP.NET

To Download a file from Web Server you can use the TransmitFile method of HttpResponse class. This function writes the file to an HTTP response output stream without buffering it in memory, see the example below,
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment; filename="+strFileName);
Response.TransmitFile(Server.MapPath("~/FileUpload/" + strFileName));
Response.End();
In the above example, downloading the file as an attachment. 

No comments:

Post a Comment