熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

ASP.NET 從服務器下載文件

2013-11-13 09:52:57  來源: .NET編程 

  string fileName = 文件名string filePath = ServerMapPath(……/DOC_FILE/) + fileName   //       ……/DOC_FILE/  下載文件的文件夾路徑if (FileExists(filePath))

  { //以字符流的形式下載文件FileStream fs = new FileStream(filePath FileModeOpen)byte[] bytes = new byte[(int)fsLength]fsRead(bytes bytesLength)fsClose()ResponseContentType = application/octetstream//通知浏覽器下載文件而不是打開ResponseAddHeader(ContentDisposition attachment filename= + HttpUtilityUrlEncode(fileName SystemTextEncodingUTF))ResponseBinaryWrite(bytes)ResponseFlush()ResponseEnd()} else { JScriptAlert(this 文件不存在!


From:http://tw.wingwit.com/Article/program/net/201311/11854.html
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.