Click here to Skip to main content
14,775,325 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello there

I have an application that downloads emails, then parses an attachment.

The attachment is an HTML template with various bits of data in it.

When I first started writing the parsing code, I used a copy of the HTML file saved directly from an email, and everything was fine.

Now, I download an email, and save the file using a function called StoreToFile() in the ActiveUp.Net.Mail library I'm using. Then I open the file with a streamreader to run it through my parsing code.

The problem I have is that when I read the file that has been downloaded automatically, the streamreader.readline() brings back a load of randomness. But when looking at both original file and the downloaded file side by side in notepad, they are identical...

First line from original file:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "">

First ReadLine from new file (Which looks identical in notepad):
line "

<\0!\0d\0o\0c\0t\0y\0p\0e\0>\0" string

I thought it maybe encoded as base 64 or something so tried converting it back, but that failed complaining of invalid characters...

Does anybody have any ideas what is going on with this? Its driving me up the wall...

Any help would be greatly appreciated...

Every second byte a null? Smells VERY strongly of a 16-bit Unicode encoding. If there isn't a byte order mark at the start of the file, your streamreader may be trying to read it as 8 bit ASCII. I'm no expert in this particular area, but I'm sure there is a way to either get StoreToFile() to write ASCII or (preferably) your streamreader to read Unicode.

Have fun,
Thanks Peter

You are right. For anyone that may come across this problem, here is what I did to get past it:
System.Text.Encoding myEncoding;
myEncoding = Text.Encoding.Unicode;
Using(StreamReader sr = New StreamReader(@"c:\Temp\temp.txt", myEncoding))
//My Code

Thanks again peter.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900