I am trying to publish articles written in Word on a website as html, I have a windows client that will convert the article to html and ship the html to a folder on the website, I then show the article in an IFrame. However in IE9 the images won’t show because IE9 tries to convert them to vector graphics. I decided to remove the code from the html that’s responsible for this and here starts my problem. After I modify and save the file I get garbage characters and these are displayed on the webpage too. However if I manually edit the file in notepad++ I don’t get the same issues, How can I read a file saved in word as html using C# and not get these garbage chars?? here is my code
private bool AdjustHtmlPageForIE9Images(FileInfo file)
{
bool success = true;
try
{
string content = File.ReadAllText(file.FullName);
//replace [if gte vml 1] with [if gte iesucksopd 1]
content = content.Replace("[if gte vml 1]", "[if gte iesucksopd 1]");
//replace [if !vml] with [if !iesucksopd]
content = content.Replace("[if !vml]", "[if !iesucksopd]");
//now write the file over
File.WriteAllText(file.FullName, content);
}
catch (Exception ex)
{
throw ex;
}
return success;
}
and this causes some garbage chars to be displayed.
Hi guys thanks for all the responses here is what I did to fix this
Hi Guys thanks for the responses finaly got it going, I had to open in FF and check the encoding and it was Western Windows-1252, then as SLaks sed pass GetEncoding(1252) in read and write operations here is the revised code.
private bool AdjustHtmlPageForIE9Images(FileInfo file)
{
bool success = true;
try
{
Encoding encoding = Encoding.GetEncoding(1252);
string content = File.ReadAllText(file.FullName,encoding);
//replace [if gte vml 1] with [if gte iesucksopd 1]
content = content.Replace("[if gte vml 1]", "[if gte iesucksopd 1]");
//replace [if !vml] with [if !iesucksopd]
content = content.Replace("[if !vml]", "[if !iesucksopd]");
//now write the file over
File.WriteAllText(file.FullName, content, encoding);
}
catch (Exception ex)
{
throw ex;
}
return success;
}
Isn’t it just ridiculous that IE9 can’t do such a simple thing as display html from word in an IFrame no wonder it’s popularity keeps falling.
You need to explicitly pass the encoding to
ReadAllTextandWriteAllText; otherwise, it will default to UTF8.Pass
Encoding.GetEncoding(1252).