Windows service and default code page/culture setting?
-
27-09-2019 - |
Question
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.
Solution
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.