2012-03-20 21 views
1

我是一個傳統的ASP頁面轉換爲.net和跨越這段代碼傳來:更新傳統的ASP方法,.exe文件,流媒體用戶

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文件流向用戶的正確方法?謝謝。

+1

可能重複http://stackoverflow.com/questions/736301/asp-net-how-to-stream-file-to-user http://stackoverflow.com/questions/5596747/download-stream-file-from-url-asp-net – Lloyd 2012-03-20 01:30:48

+0

不是,另一個是關於如何形成網址來獲取文件,然後流式傳輸,我的問題是'什麼是標準或最佳實踐! – flavour404 2012-03-20 01:40:08

+1

沒有「最好」的方法。你張貼的方式是可以接受的。 – 2012-03-20 22:24:15

回答

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)) 
+0

理查德,謝謝,我需要清理之後,沖洗什麼?謝謝,羅恩。 – flavour404 2012-03-21 19:31:06

+0

你還沒有創建任何對象,所以沒有什麼要整理:) – 2012-03-22 10:08:33