.net文件下载
文件下载:
protected void downFile(string FileName)
{
try
{
if (FileName != "")
{
string path = Server.MapPath("file\\") + FileName;
System.IO.FileInfo fi = new System.IO.FileInfo(path);
if (fi.Exists)
{
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(fi.Name));
Response.AddHeader("Content-Length", fi.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.Filter.Close();
Response.WriteFile(fi.FullName);
Response.End();
}
}
}
catch
{
Response.Write("<script language='javascript'>alert('下载失败。')</script>");// myClass.PopupMessage("下载失败!");
}
}