Silverlight: webClient stream encoding

I tried to get this to work, but now I'm very upset. I am new to this area, so maybe I'm just wrong.

What I need to do is take the .html website and save it in a txt file. Now the problem is that this site is in Russian (windows-1251 encoding), and Silverlight only supports 3 encodings. Therefore, to get around this limitation, I got an encoding class that passes a stream to an array of bytes, and then tries to extract a correctly encoded string from the text. The problem is

1) I am trying to ensure that webClient receives a Unicode encoded stream, because others do not seem to create a recoverable string, but it still does not work.

WebClient wc = new WebClient();
        wc.Encoding = System.Text.Encoding.Unicode;
        wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_LoadCompleted);
        wc.DownloadStringAsync(new Uri(site));

2) I'm afraid that when I store the html in a txt file using streamWriter, the encoding, again, is somehow messed up. 3) The coding class does not do its job.

Encoding rus = Encoding.GetEncoding(1251);
        Encoding eng = Encoding.Unicode;
        byte[] bytes = rus.GetBytes(string);
        textBlock1.Text = eng.GetString(bytes);

Can anyone help on this? This is a huge damage to my project. Thanks in advance,

+3
source share
1 answer

Since you want to handle someone else's Silverlight encoding, you should start by loading with OpenReadAsyncand OpenReadCompleted.

Now you can take Stream, provided by the event args property Result, and pass it directly to the encoding component that you purchased to generate the correct string result.

0
source

All Articles