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

ASP.NET 從服務器下載文件

2022-06-13   來源: .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-2022 電腦知識網 Computer Knowledge   All rights reserved.