notepad saves as ANSI, what about c#

Z

Ziver MALHASOGLU

Hi,

I produce a text file using my windows application written with c#.
--
System.Text.Encoding encOutput=null;
encOutput=System.Text.Encoding.UTF8;
StreamWriter sw=new StreamWriter(@"c:\a.txt",false, encOutput);
--
this UTF-8 file will be used to transfer data to another database's
import wizard. Unfortunately db that will import requires the file to be
saved as ANSI in notepad.

Always i have to open the UTF-8 encoded file with notepad and save it as
encoding ANSI in order not to have any problems.

How may i output a text file with an encoding that is compatible with
notepad's ANSI encoding...
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hi,

UTF-8 and ANSI are very different beasts. Actually, I suppose the encoding
Notepad refers to as ANSI is the Windows codepage set for the user the
application runs under.
That is, if you create a file in Notepad containing Cyrillic letters, and
your codepage is 1251 (this is Windows codepage for the Russian language),
this file will be actually saved in the 1251 encoding.

So the bottom line is - if your file contains only English letters, numbers
and special characters such as @ or #, use the ASCII encoding. This should
be read by the DB import wizard without any hassle.
If your file will contain some non-English letters, you'd better use Unicode
and tell the DB import wizard to read the file in Unicode
Or, save the file in your current codepage encoding and ensure the same
encoding is used by the DB import wizard.
 
J

Jon Skeet [C# MVP]

Ziver MALHASOGLU said:
I produce a text file using my windows application written with c#.
--
System.Text.Encoding encOutput=null;
encOutput=System.Text.Encoding.UTF8;
StreamWriter sw=new StreamWriter(@"c:\a.txt",false, encOutput);
--
this UTF-8 file will be used to transfer data to another database's
import wizard. Unfortunately db that will import requires the file to be
saved as ANSI in notepad.

Always i have to open the UTF-8 encoded file with notepad and save it as
encoding ANSI in order not to have any problems.

How may i output a text file with an encoding that is compatible with
notepad's ANSI encoding...

Just use Encoding.Default instead of Encoding.UTF8.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top