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