mathinvalidnik
mathinvalidnik

Reputation: 1600

How to copy html text selection and assign it to a string in c#

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

Answers (2)

M.R
M.R

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

xanatos
xanatos

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

Related Questions