I’m downloading a file, supposedly a .csv file, from an external URL with the following code.
MemoryStream download = new MemoryStream(client.DownloadData(targetUrl));
In the download variable theres data being populated but my problem now is actually reading that data. I tried the following:
StreamReader dataReader = new StreamReader(download,
System.Text.Encoding.Default,
true);
This and all other Encoding types are tried only return gibberish instead of the .csv data I need. Can anybody tell me how to do it?
You are reading the file data with the default system code page (
Encoding.Default) – it appears that the file is not in that encoding.You must use the encoding that the file is encoded with in order to read it successfully.
I suggest trying Unicode (UTF16), UTF8 and ASCII encodings as probable options. If none of these work as expected (that is, gibberish is produced), you need to find out the original encoding.