我正在将经典的asp页面转换为.net并遇到了这段代码:
Sub SendBinaryFile(b_FileName)
tool = Server.MapPath("bin/" & b_FileName)
Response.AddHeader "Content-Disposition", "attachment;filename=" & b_FileName
Response.ContentType = "application/octet-stream"
Set BinaryStream = CreateObject("ADODB.Stream")
BinaryStream.Open
BinaryStream.Type = 1
BinaryStream.LoadFromFile tool
Response.BinaryWrite BinaryStream.Read
BinaryStream.Close
Set BinaryWrite = Nothing
End Sub
我之前没有在.net中这样做过,所以我想知道将.exe文件流式传输给用户的'正确方法是什么?感谢。
答案 0 :(得分:1)
在.Net中简单得多....
tool = Server.MapPath("bin/" & b_FileName)
Response.AddHeader("Content-Disposition", "attachment;filename=" & b_FileName)
Response.ContentType = "application/octet-stream"
Response.BinaryWrite(File.ReadAllBytes(tool))