Search code examples
c#uwpfilepicker

UWP, loading csv file with correct encoding


When I want to load a csv file that includes letter "ş", "ü", it gives me �.

my codes are like below;

var picker = new Windows.Storage.Pickers.FileOpenPicker();
        picker.FileTypeFilter.Add(".csv");

        Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();
        if (file!=null)
        {
            string[] lines = File.ReadAllLines(file.Path);
            for (int i = 1; i < lines.Count(); i++)
            {
                data2 = lines[i].Split(';');

As far as I found on internet, I need to use iso-8859-9 encoding but I dont know how to apply to my codes.


Solution

  • It is an encoding problem. File.ReadAllLines uses UTF-8 by default. Below code should work

    string[] lines = File.ReadAllLines(file.Path,  Encoding.GetEncoding("Windows-1254"));
    

    PS: You may also try with ISO-8859-9 instead of Windows-1254