I have an htm-file, lets call it somehtml.htm, with some HTML that I want to collect by using the File.ReadAllText()-method.
somehtml.htm:
<div>
<h1>A heading</h1>
<p>A paragraph</p>
</div>
When I do this:
string temp = System.IO.File.ReadAllText(“somehtml.htm”);
…the result is this:
<div>\r\n
<h1>A heading</h1>\r\n
<p>A paragraph</p>\r\n
</div>\r\n
And this doesn’t look good when displayed…
According to the documentation for File.ReadAllText, this method is NOT supposed to add \r\n to the resulting string, even though the file contains carriage return and line feed.
Most probably your file contains these already.
MSDN is correct –
ReadAllTextdoes not add anything to the file.Look at your file with a text editor that shows you
\r\n.