<% dim ModuleName,InfoID,ChannelShortName,CorrelativeArticle,InstallDir,ChannelDir,Keyword,PageTitle,ArticleIntro,Articlecontent Keyword=stripHTML("ASP.NET") PageTitle=stripHTML("ASP.NET 从服务器下载文件") ArticleIntro=stripHTML("") Articlecontent=stripHTML("string fileName = “文件名;string filePath = Server.MapPath(……/DOC_FILE/) + fileName…") ModuleName = stripHTML("programme") InfoID = stripHTML("113896") ChannelShortName=stripHTML("编程") InstallDir=stripHTML("http://www.77169.com/") ChannelDir=stripHTML("programme") %> ASP.NET 从服务器下载文件 - 华盟网 - http://www.77169.com
您现在的位置: 华盟网 >> 编程 >> asp编程 >> 正文

ASP.NET 从服务器下载文件

2012/1/17 作者:不行 来源: 华盟收集
导读 <% if len(ArticleIntro)<3 then Response.Write Articlecontent 'Response.Write "Articlecontent" else Response.Write ArticleIntro 'Response.Write "ArticleIntro" end if %>
string fileName = “文件名";string filePath = Server.MapPath("……/DOC_FILE/") + fileName;   //       ……/DOC_FILE/  下载文件的文件夹路径if (File.Exists(filePath))

  { //以字符流的形式下载文件FileStream fs = new FileStream(filePath, FileMode.Open);byte[] bytes = new byte[(int)fs.Length];fs.Read(bytes, 0, bytes.Length);fs.Close();Response.ContentType = "application/octet-stream";//通知浏览器下载文件而不是打开Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));Response.BinaryWrite(bytes);Response.Flush();Response.End();} else { JScript.Alert(this, "文件不存在!");