Showing posts with label save to client. Show all posts
Showing posts with label save to client. Show all posts

Monday, October 13, 2008

Export file to client

Following function downloads specified file from server to client.

=============================================

public static void DownloadFiles(string FileName)
{
HttpContext context = HttpContext.Current;
context.Response.AddHeader("Content-Disposition", "attachment; filename=" + FileName);
context.Response.ContentType = "application/xml";
string Path = context.Server.MapPath(FileName);

try
{
context.Response.WriteFile(Path);
}
catch (Exception ex) { }
context.Response.Flush();
context.Response.End();
}