C # encoding problems (question marks) while reading a file from StreamReader

I have a problem reading a .txt file from my Windows Phone application.

I made a simple application that reads a stream from a TXT file and prints it.

Unfortunately, I am from Italy and we have many letters with accents. And here is the problem, because all letters with an accent are printed as a question mark.

Here is a sample code:

var resourceStream = Application.GetResourceStream(new Uri("frasi.txt",UriKind.RelativeOrAbsolute));
            if (resourceStream != null)
            {
                {
                    //System.Text.Encoding.Default, true
                    using (var reader = new StreamReader(resourceStream.Stream, System.Text.Encoding.UTF8))
                    {
                        string line;
                        line = reader.ReadLine();

                        while (line != null)
                        {
                            frasi.Add(line);
                            line = reader.ReadLine();       
                        } 
                    }
                }

So, I ask you how to avoid this.

All the best.

[EDIT:] Solution: I did not make sure that the file was encoded in UTF-8. I saved it with the correct encoding, and it worked like a charm. thank you oscar

+3
source share
2 answers

You need to use Encoding.Default. Change:

using (var reader = new StreamReader(resourceStream.Stream, System.Text.Encoding.UTF8))

to

using (var reader = new StreamReader(resourceStream.Stream, System.Text.Encoding.Default))
+12
source

, , . System.Text.Encoding.Default ANSI . / .

MSDN :

, . , , . , , Default, , . . , , Unicode, ​​ UTF8Encoding UnicodeEncoding, . , .

, , , , ... Esp. , ANSI UTF8.

, .

+1

All Articles