I am trying to read text files that contains some danish characters. I have found a few ways to do it using different types of encoding but the examples I have seen are reading just one file. This is what I have so far.
//search directory for all .txt files
foreach (string files in Directory.GetFiles(@"C:\ftp\inbox", "*.txt"))
{
//The 'using' command close connection when it is done
using (var reader = new StreamReader(File.OpenRead(files)))
{
// Handle contents
}
}
My problem is all the characters are being read as �. I need them to be read in as they are.
I resolved the issue by changing:
using (var reader = new StreamReader(File.OpenRead(files)))
into
using (var reader = new StreamReader(files, System.Text.Encoding.GetEncoding("iso-8859-1")))
and now the danish characters are read in as they should be.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With