Dear Friends,

In my C# desktop application, I get the startup path from Application.StartupPath.Then my program creates a batch file, which changes the directory (with cd) to the above startup path (since sometimes it runs batches which changes the current directory).
In English windows it works great. But on Spanish Windows, my app's startuppath contains accent. So when I view the batch file I created, it has invalid characters where accent was before.
I create the batch file in the following way:

StreamWriter sw = new StreamWriter("a.bat"); sw.WriteLine("cd " + Application.StartupPath); sw.Close();

As I described, in a.bat I'll find that path corrupted where the accent originally appears.
Note that in MSDN documentation, it says that StreamWriter always uses UTF-8.

How can I avoid this problem?

Please help, it's very urgent.

Thanks deeply,
Ohad.

You can specify the encoding used in the streamwriter

new StreamWriter(@"C:\path\", false, Encoding.Default);

Thanks much for the fast reply. But it didn't work.
I had a mistake in my last post, and I used:

StreamWriter sw = File.CreateText("p.bat");

But, neither the following two works:

StreamWriter sw = new StreamWriter("p.bat", false, Encoding.Default);
StreamWriter sw = new StreamWriter("p.bat", false, Encoding.UTF8);

In the batch there are still garbage characters where chars with accent should be.

Please help, and many many thanks.

Wouldn't it be using Unicode encoding and not UTF8 for spanish? Let me look around some more

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.