Wednesday, July 27, 2011

download box instead of direct open file in new window.

#region download-file
static public void DownloadFile(string filePath)
{
try
{
filePath = filePath.Replace(" ", "_");
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + System.IO.Path.GetFileName(filePath));
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.WriteFile(filePath);
HttpContext.Current.Response.End();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion

No comments:

Post a Comment

ASP.NET Core

 Certainly! Here are 10 advanced .NET Core interview questions covering various topics: 1. **ASP.NET Core Middleware Pipeline**: Explain the...