Hi, Gurus,
I am developing an application which can automatically download updated version (as .exe file). I am wondering what kind of encoding or code should i use in .net, my following code seems to work only for .txt file. Thanks.
*****************************************************
Public Function WebDownload(ByVal remoteFileFullUrl As String, ByVal localFilePath As String, ByVal proxyserver As String, Optional ByVal proxyport As String = "80") As Boolean
Dim proxyObject As WebProxy
Dim webreq As HttpWebRequest
Dim webresp As HttpWebResponse
Dim strm As StreamReader
' Create a HttpWebRequest object on the url
webreq = HttpWebRequest.Create(remoteFileFullUrl)
If proxyserver <> "" Then
proxyObject = New WebProxy(proxyserver, True)
webreq.Proxy = proxyObject
End If
' Get a HttpWebResponse object from the url
webresp = webreq.GetResponse()
' Create a StreamReader object and pass the stream as a parameter
strm = New StreamReader(webresp.GetResponseStream(), Encoding.ASCII)
Dim myFile As System.IO.FileStream
myFile = IO.File.Create(localFilePath)
Dim ret As String
' Read each line from the stream (from the server)
While strm.Peek() > -1
ret = strm.ReadLine()
myFile.Write(Encoding.ASCII.GetBytes(ret), 0, ret.Length())
End While
myFile.Close()
' Close the stream to the server and free the resources.
strm.Close()
webresp.Close()
End Function