views:

553

answers:

2

Hello, how can I save all files in a directory using utf-8?

There is a need to change the default file encoding in IIS to display all foreign characters correct. The problem is: all old files are saved in (different/random) encodings.

Is there a way to open (in current) and save all those files safely to UTF-8?

A: 

If the files are text files then you can use the overloaded System.IO.File.WriteAllText() method and pass the UTF-8 encoding type. That should do the trick

Kane
I wrote a small program to ReadAllText and simply writealtext again using utf-8 encodung. this worked pretty fine. Thank you!
Uwe
A: 

If you are using Visual Studio 2005 or 2008, you can change the encoding a file is saved with using File -> Advanced Save Options. You'll need to potentially do that for each file (though you can probably get away with doing it only to those files in which you have internationalized content).

That said - be sure that when you render HTML to the user's browser that you are setting the encoding type with a meta tag in the head. The specific tag will be:

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
John Christensen