views:

40

answers:

1

Hi,

I'm writing a service that will read a file from a directory, read the contents of the file and process the content.

I am having issues with Swedish characters that are read from the file as they are beeing translated into "garbage chars" by the service when they are read.

Does anyone know what default code page/culture setting is beeing used by the Service Control Manager or perhaps you know of any article about "best practice" for handling Swedish characters in the context of Windows Service programming?

Any help is appreciated.

A: 

It has probably some thing to do with how you read the file and how the file is encoded. For example if the file is encoded with UTF-8 and your reading it with ASCII then the special characters will be garbage.

For example:

using (var fileStream = new StreamReader(@"path to file", Encoding.UTF8))
{
    Console.Write(fileStream.ReadToEnd());
}

You can change Encoding.UTF8 to match the encoding used to create the file.

Jens Granlund
Thank you for your pointer. I just had to figure out which encoding to use and that made it work. I used Encoding.GetEncoding(1252) in the StreamReader construtcor and that made my day. Thank you!
Freddy