DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Downloading A File In Asp.net

01.27.2012
| 1963 views |
  • submit to reddit
        // downloading a file in asp.net


                string attachment = "attachment; filename=" + file;
                HttpContext.Current.Response.ClearContent();
                HttpContext.Current.Response.AddHeader("content-disposition", attachment);
                HttpContext.Current.Response.ContentType = "application/text";
                HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default;
                HttpContext.Current.Response.TransmitFile(string.Concat(DownloadFilePath));
                HttpContext.Current.Response.End();