I'm reading the content from a page using DownloadString
from the WebClient
class and then writing the contents of that to a static HTML file using the StreamWriter
class. On the page that I'm reading in, there's an inline javascript method that just sets an anchor element's OnClick
attribute to set the window.location = history.go(-1);
I'm finding when I view the static HTML page, there's an odd looking letter showing up that isn't present on the dynamic web page.
WebClient & SteamWriter Code
using (var client = new WebClient())
{
var html = client.DownloadString(url);
//This constructor prepares a StreamWriter (UTF-8) to write to the specified file or will create it if it doesn't already exist
using (var stream = new StreamWriter(file, false, Encoding.UTF8))
{
stream.Write(html);
stream.Close();
}
}
The dynamic page's HTML snippet in question
<span>Sorry, but something went wrong on our end. Click <a href="#" onclick="window.location.href = history.go(-1);">here</a> to go back to the previous page.</span>
The static page's HTML snippet
<span>Sorry, but something went wrong on our end. Â Click <a href="#" onclick="window.location.href = history.go(-1);">here</a> to go back to the previous page.</span>
I was thinking that adding the Encoding.UTF8
parameter would solve this issue but it didn't seem to help. Is there some sort of extra encoding or decoding that I need to do? Or did I completely miss something else that's needed for this type of operation?