Im writing a sub in one of my VB programs for downloading .exe files from an HTTP server to the local machine. But when ever the file is downloaded it appears to be corrupted because no icon shows on the file and it wont run. The same code works fine for ordinary HTML pages but not exes it seems. Can anyone help with this problem? - heres the sub:
Code:
Dim v_base As String = "http://www.talbotech.com/"
Public Sub GetFile(ByVal uri As String, ByVal toFile As String)
Dim wreq As Net.HttpWebRequest = Net.WebRequest.CreateDefault(New Uri(v_base & uri))
wreq.AllowAutoRedirect = True
wreq.Proxy = Net.WebProxy.GetDefaultProxy
Dim resI As Net.HttpWebResponse = wreq.GetResponse
Dim wres As IO.StreamReader = New IO.StreamReader(resI.GetResponseStream, System.Text.Encoding.Default)
Dim buff(resI.ContentLength - 1) As Char
wres.Read(buff, 0, buff.Length)
Dim fileIO As IO.StreamWriter = New IO.StreamWriter(IO.File.Open(toFile, IO.FileMode.Create), System.Text.Encoding.Default)
fileIO.Write(buff, 0, buff.Length)
fileIO.Close()
wres.Close()
resI.Close()
End Sub