我将一个公用的下载代码写到cs文件里面 代码如下
public void DownFile(string strDownFile)
{
string str=Server.MapPath(strDownFile);
if(System.IO.File.Exists(str))
{
System.IO.FileInfo fi=new System.IO.FileInfo(str);
System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.ClearHeaders();
System.Web.HttpContext.Current.Response.Buffer = false;
System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream";
System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename=" +HttpUtility.UrlEncode(fi.FullName,System.Text.Encoding.UTF8));
System.Web.HttpContext.Current.Response.AppendHeader("Content-Length",fi.Length.ToString());
System.Web.HttpContext.Current.Response.WriteFile(fi.FullName);
System.Web.HttpContext.Current.Response.Flush();
System.Web.HttpContext.Current.Response.End();
}
else
{
new Login.TLogin().MsgBox("文件未找到!");
}
}
可以是运行时 有些机器能提示下要下载的文件 有些缺提示保存页面 如果下载aa.doc 有的机器会提示请aa.doc的下载保存对话框 而有的机器上会提示down.aspx?id=120的下载保存对话框 不知道是那里错了