A StreamReader uses UTF-8 encoding by default, so you could try modifying your code slightly:
vb.net Code:
Dim myString As String ' declared here to broaden its Scope Using myWebClient As New Net.WebClient() Using myStream As IO.Stream = myWebClient.OpenRead(url) Using sr As New IO.StreamReader(myStream, System.Text.Encoding.GetEncoding("ISO-8859-1")) myString = sr.ReadToEnd End Using ' Stream End Using ' StreamReader End Using ' WebClient
The WebClient.Encoding Property is used by the WebClient when it uploads or downloads Strings, so you might also try:
although it defaults to the system's default encoding, so you could probably get away without explicitly setting the encoding in your particular case. It's best to set it explicitly when you can, though. See the MSDN for more details, and also the Remarks section here.vb.net Code:
Dim myString As String ' declared here to broaden its Scope Using myWebClient As New Net.WebClient() myWebClient.Encoding = System.Text.Encoding.GetEncoding("ISO-8859-1") mystring = myWebClient.DownloadString(url) End Using ' WebClient




Reply With Quote