1

I am converting a classic asp page to .net and came across this piece of code:

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

I have not done this before in .net so I am wondering what is the 'correct way to stream a .exe file to the user? Thanks.

flavour404
  • 6,184
  • 30
  • 105
  • 136
  • 1
    Possible duplicate 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 Mar 20 '12 at 01:30
  • Not really, the other one is regarding how to form the url to get the file and then stream it, my question is 'what is the standard or best practice! – flavour404 Mar 20 '12 at 01:40
  • 1
    There isn't a 'best' way. The way you posted is acceptable. – Michael Pryor Mar 20 '12 at 22:24

1 Answers1

1

It's a lot simpler in .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))
Richard Benson
  • 1,477
  • 12
  • 20