Reputation: 131
I create a C# soft which take as parameter a CSV which contain a list of folder like :
I read the file whis this code :
public projectTree(string _path)
{
path = _path;
try
{
confFile = File.ReadAllText(path);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Fichier", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
lines = confFile.Split('\n');
foreach (string line in lines)
{
try
{
FolderInfo tmp = new FolderInfo();
if (line.IndexOf(';') >= 0)
{
if (line.Split(';')[1].Count() > 0)
tmp.name = line.Split(';')[1];
else
tmp.valid = false;
if (line.Split(';')[2].Count() > 0)
tmp.RACL_ReadOnly = line.Split(';')[2];
else
tmp.valid = false;
if (line.Split(';')[3].Count() > 0)
tmp.RACL_Users = line.Split(';')[3];
else
tmp.valid = false;
if (line.Split(';')[4].Count() > 0)
tmp.RACL_Managers = line.Split(';')[4];
else
tmp.valid = false;
if (line.Split(';')[5].Count() > 0)
tmp.RACL_Partners = line.Split(';')[5];
else
tmp.valid = false;
if (tmp.valid == true)
{
ACLs.Add(tmp);
}
}
}
catch
{
return;
}
}
}
The soft create folders from this list but when creating the "02-Ôlololéééèèç" folder, the folder is created as :
How can I handle this characters ?
Upvotes: 0
Views: 586
Reputation: 2917
When reading files make sure to specify the encoding - especially when reading non-UTF-8 encoded files. If you are unsure of a file's encoding, you can open it in Notepad++ or any other text editor capable of handling various encodings, and simply look it up:
Default ANSI encoding for Wester European languages is Windows 1252, so you need to change your reading line to:
confFile = File.ReadAllText(path, Encoding.GetEncoding(1252));
Upvotes: 1