Sunday, January 11, 2009

Prompt Download File in ASP.Net Csharp

string path = Server.MapPath("##FILEPATH##");
System.IO.FileInfo fi = new FileInfo(path);

Response.Clear();
Response.AddHeader("Content-Disposition", "attachment;filename=" + fi.Name);
Response.ContentType = "application/octstream";
Response.AddHeader("Content-Length", fi.Length.ToString());
Response.TransmitFile(path);
Response.Flush();
Response.Clear();

No comments:

Post a Comment