A: 

I do not know why It works with NUnit, but I open the file with NotePad++ and I see ANSI in the format. Now I converted to UTF-8 and it works.

I am still wondering why it was working with NUnit and not in the console? but at least it works now.

Update I do not get why I get down voted on the question and in this answer because the question is still good, why in a Console I can't read an ANSI file but in NUNit I can?

Daok
As long as you're just adding info to your original question, don't add a response. Simply edit your original question. That might explain some of the downvote(s).
Tanktalus
I haven't added information before I got downvoted. I found some information new to I post it.
Daok
+3  A: 

The .NET classes (System.IO.StreamReader and the likes) take UTF-8 as the default encoding. If you want to read a different encoding you have to pass this explicitly to the appropriate constructor overload.

Also note that there's not one single encoding called “ANSI”. You're probably referring to the Windows codepage 1252 aka “Western European”. Notice that this is different from the Windows default encoding in other countries. This is relevant when you try to use System.Text.Encoding.Default because this actually differs from system to system.

/EDIT: It seems you misunderstood both my answer and my comment:

  1. The problem in your code is that you need to tell .NET what encoding you're using.
  2. The other remark, saying that “ANSI” may refer to different encodings, didn't have anything to do with your problem. It was just a “by the way” remark to prevent misunderstandings (well, that one backfired).

So, finally: The solution to your problem should be the following code:

string text = System.IO.File.ReadAllText("path", Encoding.GetEncoding(1252));

The important part here is the usage of an appropriate System.Text.Encoding instance.

However, this assumes that your encoding is indeed Windows-1252 (but I believe that's what Notepad++ means by “ANSI”). I have no idea why your text gets displayed correctly when read by NUnit. I suppose that NUnit either has some kind of autodiscovery for text encodings or that NUnit uses some weird defaults (i.e. not UTF-8).

Oh, and by the way: “ANSI” really refers to the “American National Standards Institute”. There are a lot of completely different standards that have “ANSI” as part of their names. For example, C++ is (among others) also an ANSI standard.

Only in some contexts it's (imprecisely) used to refer to the Windows encodings. But even there, as I've tried to explain, it usually doesn't refer to a specific encoding but rather to a class of encodings that Windows uses as defaults for different countries. One of these is Windows-1252.

Konrad Rudolph
Ansi format in Notepad++ : http://img359.imageshack.us/img359/9194/ansinz4.pngAnd in Wiki : http://en.wikipedia.org/wiki/ASCII and http://en.wikipedia.org/wiki/ANSI_escape_code
Daok
Apart from the fact that these links all refer to things, the first picture (showing Notepad++) is just an imprecise usage of the word in context. What they probably mean here is the same as .NET's `Default` encoding, namely the current system's default codepage, not one specific encoding.
Konrad Rudolph
I show you that Notepad++ show me that it wasn't in UTF8... and you tell me that ANSI doesn't exist when it's false from many source. I did my research and I should you. But you still can't understand me? I am not a Encoding master that I've to understand all what you do. A
Daok
At least I am trying to solve my problem. NUNIT and the console application is in the SAME machine so I do not get why you told me the answer with system to system.The file encoding is the same for both, and both are open with the default loading encoding of Net.So your answer isn't better than mine
Daok
I am glad you take time to try to help me. But if you think my question is stupid, just do not post something. Someone else will find it good and will help me.
Daok
THANK YOU for the edit. Now I understand more.
Daok
+1  A: 

Try setting your console sessin's output code page using the chcp command. The code pages supported by windows are here, here, and here. Remember, fundametnaly the console is pretty simple: it displays UNCICODE or DBCS characters by using a code page to dtermine the glyph that will be displayed.

Foredecker