Special characters and Encoding text in C#?

I've been programming an application to read some of the information from my personal web page, I know it's not the best code out there. unfortunatly it has NOT worked for me when i get special characters like the ones used in spanish or french; á, é, í, ó, ú and others

"más percusión"

comes out as:

- "más percusión"

So when I save some of the info in a DB it saves it with weird chars or a "?" simbol, not the correct ones.

I am using the Encoding 1252, Any idea how to fix the problem?

I tried using the line:

return System.Text.Encoding.GetEncoding(1252).GetString(Encoding.GetEncoding(1252).GetBytes(todo_1.ToCharArray()));


 It started to work, But i dont know why.  Now I get just a "?" simbol instead of the right char.

Thanks for the help!
public string getDocumento_Txtx(string direccion)
        {
            System.Net.WebClient Client = new WebClient();
            Stream strm = null;
            try
            {
                strm = Client.OpenRead(direccion);
            }catch(Exception r)
            {
                if (r.Message.Contains("404"))
                    return "Archivo Inexistente";

            }
            StreamReader sr = new StreamReader(strm,    System.Text.Encoding.GetEncoding(1252));
            string line = "";
            string todo_1 = "";
            do
            {

                line = sr.ReadLine();


                todo_1 = todo_1 + Environment.NewLine + line;

            }
            while (line != null);

            strm.Close();

            return todo_1;

        }

Open in new window

LVL 1
rperezretanaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rperezretanaAuthor Commented:
I already saved the content in a text file, but.. same, it saves the "?" chars like:

"más percusión"

comes out as:

- "m?s percusi?n"
0
DanielD2004Commented:
Try UTF8.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rperezretanaAuthor Commented:
Actually that one was verry good!!...

I used this code and it worked ;)
StreamReader sr = new StreamReader(strm,Encoding.UTF8);

Open in new window

0
rperezretanaAuthor Commented:
Thanks for help:
I used like this:


StreamReader sr = new StreamReader(strm,Encoding.UTF8);
 and now its working
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.