System.IO.FileInfo file;
here sFile = your virtual file path (/myfiles/abc.xls)
file = new System.IO.FileInfo(sFile);
if (file.Exists)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;
filename=" + file.Name);
HttpContext.Current.Response.AddHeader("Content-Length", file.Length.ToString());
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
HttpContext.Current.Response.WriteFile(file.FullName);
HttpContext.Current.Response.End();
System.GC.Collect();
}
else
{
HttpContext.Current.Response.Write("This file does not exist.");
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment