`
joerong666
  • 浏览: 410082 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

ASP.NET下载文件(弹出打开保存文件对话框)

    博客分类:
  • c#
阅读更多
ASP.NET下载文件(弹出打开保存文件对话框) //fileURL为带路径的文件全名 System.IO.FileInfo fileInfo = new System.IO.FileInfo(fileURL); Response.Clear(); Response.AddHeader("content-disposition","attachment;filename="+Server.UrlEncode(fileInfo.Name.ToString())); Response.AddHeader("content-length",fileInfo.Length.ToString()); Response.ContentType = "application/octet-stream"; Response.ContentEncoding = System.Text.Encoding.Default; Response.WriteFile(fileURL); 无错版: try ...{ FullFileName = Server.MapPath(FileName); //FileName--要下载的文件名 FileInfo DownloadFile= new FileInfo(FullFileName); if(DownloadFile.Exists) ...{ Response.Clear(); Response.ClearHeaders(); Response.Buffer=false; Response.ContentType="application/octet-stream"; Response.AppendHeader("Content-Disposition","attachment;filename=" +HttpUtility.UrlEncode(DownloadFile.FullName,System.Text.Encoding.ASCII)); Response.AppendHeader("Content-Length",DownloadFile.Length.ToString()); Response.WriteFile(DownloadFile.FullName); Response.Flush(); Response.End(); } else ...{ //文件不存在 } } catch ...{ //文件不存在 }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics