ASPNET文件下载函数使用是什么情况呢?在你的Page_Load中添加这样的代码:
PageResponseClear(); bool success = ResponseFile(PageRequest PageResponse 目的文件名称 @源文件路径 ); if (!success) ResponseWrite(下载文件出错!); PageResponseEnd();
ASPNET文件下载函数代码为:
public static bool ResponseFile(HttpRequest _RequestHttpResponse _Responsestring _fileNamestring _fullPath long _speed) { try { FileStream myFile = new FileStream(_fullPath FileModeOpen FileAccessRead FileShareReadWrite); BinaryReader br = new BinaryReader(myFile); try { _ResponseAddHeader(AcceptRanges bytes); _ResponseBuffer = false; long fileLength = myFileLength; long startBytes = ; double pack = ; //K bytes //int sleep = ; //每秒次 即*K bytes每秒 int sleep = (int)MathFloor( * pack / _speed) + ; if (_RequestHeaders[Range] != null) { _ResponseStatusCode = ; string[] range = _RequestHeaders[Range]Split(new char[] {= }); startBytes = ConvertToInt(range[]); } _ResponseAddHeader(ContentLength (fileLength startBytes)ToString()); if (startBytes != ) { //ResponseAddHeader(ContentRange stringFormat( bytes {}{}/{} startBytes fileLength fileLength)); } _ResponseAddHeader(Connection KeepAlive); _ResponseContentType = application/octetstream; _ResponseAddHeader(ContentDispositionattachment;filename= + HttpUtilityUrlEncode(_fileNameSystemTextEncodingUTF) ); brBaseStreamSeek(startBytes SeekOriginBegin); int maxCount = (int) MathFloor((fileLength startBytes) / pack) + ; for (int i = ; i < maxCount; i++) { if (_ResponseIsClientConnected) { _ResponseBinaryWrite(brReadBytes(intParse(packToString()))); ThreadSleep(sleep); } else { i=maxCount; } } } catch { return false; } finally { brClose(); myFileClose(); } } catch { return false; } return true; }
这样就实现了文件下载时不管是什么格式的文件都能够弹出打开/保存窗口
ASPNET文件下载函数的基本情况就向你介绍到这里希望对你了解ASPNET文件下载函数有所帮助