troubleshooting Question

reading encoded characters

Avatar of stevesuch
stevesuch asked on
C#
5 Comments1 Solution280 ViewsLast Modified:
I'm currently having a problem with reading the text from a file on the server that contains special characters.
The text I am tryng to read is:
"Promoter Shirt Brand Name® Product Name""

and I'm using the following method
StreamReader sr = new StreamReader(InputFilePath);
string test = sr.ReadToEnd();

This returns in .NET (note that the trademark/copyright symbols are now gone):
"Promoter Shirt Brand Name ý Product Name ý "

The same result is produced when I specify other encloding values
new StreamReader(InputFilePath,Encoding.UTF8);
new StreamReader(InputFilePath,Encoding.ASCII);
new StreamReader(InputFilePath,Encoding.Unicode);

When I create a new file on my system, copy and paste the contents of the original text file into it and save it (with UTF-8) encoding then it works as expected, displaying the symbols correctly.

Is there a method to read this data whatever the encoding of the file being loaded?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 5 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros