日期:2014-05-17 浏览次数:20644 次
private void DownLoad(string filepath, string filetitle) { System.IO.FileInfo fi=new System.IO.FileInfo(filepath); 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(filetitle, 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(); }
------解决方案--------------------
添加这样一句话Response.AppendHeader("Content-Disposition","attachment;filename=aa.xls");
filename=aa.xls
表示打开/保存/取消的文件名
------解决方案--------------------
友情UP
------解决方案--------------------
这个异常现象倒是没碰到过...
------解决方案--------------------
图片下载
public void SavePhotoFromUrl(string address, string FileName) { System.Net.WebClient wc = new System.Net.WebClient(); try { wc.DownloadFile(address, FileName); Response.Write("<script>alert('远程文件已经下载完毕!地址为" + filename + "')</script>"); } catch (System.Exception ex) { Response.Write("error:" + ex.Message.ToString()); } }
------解决方案--------------------
这样一来解决了`你所描述的问题了``
------解决方案--------------------