Reputation: 1600
I have an .html file containing only text(formatted somehow).I am wondering if there is a way to copy all of the text(like if would do with ctrl+A) and assign it to a string So I can then export it to .txt file ? All this must happen from the code-behind(opening the html, selecting the text and assigning it to a string).
In the Microsoft.Office.Interop
I remember that there was an option for copying the active window selection or something, so I was wondering if this is possible and here.
Upvotes: 1
Views: 1337
Reputation: 526
use this for read from file
using (StreamReader sr = new StreamReader("TestFile.html"))
{
String line = sr.ReadToEnd();
Console.WriteLine(line);
}
http://msdn.microsoft.com/en-us/library/db5x7c0d.aspx
and this for read from url
WebClient client = new WebClient();
String htmlCode = client.DownloadString("http://test.com/file.html");
Upvotes: 0
Reputation: 111940
Use HttpAgilityPack. Someone could say it's overblown, but otherwise tomorrow you'll ask us how to convert the &code; that are in the file, and the next day you'll ask something else.
Upvotes: 1