I have a stream coming in from a HttpWebResponse and when I am using the code below to read and basically re-create the file on my local machine.
string sx = "";
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
using (Stream resStream = response.GetResponseStream())
{
StreamReader reader = new StreamReader(resStream, Encoding.Default); // I have also tried using Encoding.UTF8/7/ASCII etc.
sx = reader.ReadToEnd();
// sourceItem.Name would have the file name along with the extension.
using (StreamWriter sw = System.IO.File.AppendText(sourceItem.Name))
{
sw.Write(sx);
}
}
response.Close();
}
But when I open the file on my local machine, I get all weird garbage symbols.
Picture:
Garbage characters and symbols
I believe this is a problem with encoding of the files.
I used file *
on git bash to check the encoding and it turns out, it's Little Endian.
Little Endian Screenshot
But unfortunately, I cannot see Little Endian in System.Text.Encoding
.
How do I fix my problem?
Thanks for the help.