【asp源码栏目提醒】:网学会员为广大网友收集整理了,asp net 文件下载功能函数代码整理 - 综合课件,希望对大家有所帮助!
asp net 文件下载功能函数代码整理 asp.net文件下载功能函数代码整理2010-12-12 1905public void FileDownLoadDelstring fullFilename System.IO.Stream iStreamnull //Buffer to read 10K bytes in chunk byte buffernew Byte10000 //Length of the file int length //Total bytes to read long dataToRead //Identify the file to download including its path. string filepathfullFilename filepathServer.MapPathfilepath //Identify the file name. string filenameSystem.IO.Path.GetFileNamefilepath try //Open the file. iStreamnew System.IO.FileStreamfilepathSystem.IO.FileMode.Open System.IO.FileAccess.ReadSystem.IO.FileShare.Read //Total bytes to read dataToReadiStream.Length Response.ContentTypeapplication/octet-stream Response.AddHeaderContent-Dispositionattachmentfilenamefilename //Read the bytes. whiledataToRead 0 //Verify that the client is connected. ifResponse.IsClientConnected //Read the data in buffer. lengthiStream.Readbuffer010000 //Write the data to the current output stream. Response.OutputStream.Writebuffer0length //Flush the data to the HTML output. Response.Flush buffernew Byte10000 dataToReaddataToRead-length else //prevent infinite loop if user disconnects dataToRead-1 Response.Clear Response.End//没有这句会将该页面刷新后的内容追加写入文件中。