Pomster
Pomster

Reputation: 15207

I want to select all and copy it to clipboard

I have a WebBrowser displaying text. If i copy it to clipbaord it copy's all the html tags to and i don't want that.

I want to be able to select all then copy to clipboard.

I want to copy the text and its formatting to the clipboard.

When i highlight the text my self and click copy when i paste, its perfect just how i want it.

But when i use this code to copy just the Document text i get the Html tags to.

This is how i copy to clipboard:

void CopyCellText()
{
Clipboard.Clear();
if (webBrowser1 != null)
{
Clipboard.SetText(webBrowser1.DocumentText.ToString().Trim());
}
}

Upvotes: 1

Views: 4103

Answers (4)

Pomster
Pomster

Reputation: 15207

To Select all and copy to clipboard:

webBrowser1.Document.ExecCommand("SelectAll", true, null);
webBrowser1.Document.ExecCommand("Copy", true, null);

You wont see the html tags but have all there formatting.

Upvotes: 3

markhlong
markhlong

Reputation: 55

I think the reason you are getting the HTML tags is webBrowser1.DocumentText will take the entire content of the HTML document itself, which will include all the generated HTML.

A quick search gave me the following:

Retrieving Selected Text from Webbrowser control in .net(C#)

Get all text from WebBrowser control

Upvotes: 1

davee
davee

Reputation: 156

http://www.dreamincode.net/code/snippet1921.htm << check this code snippet. it would be better, if you strip the string while using regex!

Upvotes: 1

Chibueze Opata
Chibueze Opata

Reputation: 10044

You mean you want to convert your html code to text and copy to clipboard? You will need HTML Agility Pack. Check this page for an easy guide.

Upvotes: 1

Related Questions