Invalid characters (square boxes) while reading a text file (encoding issue)
While reading a text file we get square symbols in .NET for special symbols. For e.g ° .
However if the file is created\saved as Unicode then the file is read correctly.
- tried encoding.UTF-8 but still get the error string
- notepad opens up the file correctly with the special characters
Use encoding "Windows-1252".
Sample code -
using (StreamReader reader = new StreamReader(filePath, System.Text.Encoding.GetEncoding("Windows-1252")))
string content = reader.ReadToEnd();