public static void ReturnHTTPStream(string filePath)
{
FileInfo fi = new FileInfo(filePath);
//HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + fi.Name);
HttpContext.Current.Response.AddHeader("Content-Length", fi.Length.ToString());
HttpContext.Current.Response.AppendHeader("Last-Modified", fi.LastWriteTime.ToFileTime().ToString());
HttpContext.Current.Response.AppendHeader("Location", HttpContext.Current.Request.Url.AbsoluteUri);
HttpContext.Current.Response.ContentType = GetResponseContentType(fi.Extension);
HttpContext.Current.Response.WriteFile(filePath);
HttpContext.Current.Response.End();
}
private static string GetResponseContentType(string fileType)
{
string result;
switch (fileType.ToLower())
{
case ".doc": result = "application/msword"; break;
case ".xls":
case ".xlt": result = "application/msexcel"; break;
case ".txt": result = "text/plain"; break;
case ".pdf": result = "application/pdf"; break;
case ".ppt": result = "appication/powerpoint"; break;
default: result = "application/unknown"; break;
}
return result;
}