Blatfrig
Blatfrig

Reputation: 591

Copying from WebBrowser Control

I have the following code in my C# windows app which places the data from my webbrowser control into the clipboard. However when I come to pasting this into MSWord it pastes the HTML markup rather than the contents of the page.

Clipboard.SetDataObject(WebBrowser.DocumentText, true);

Any Idea how I can get around this?

Upvotes: 2

Views: 9105

Answers (4)

abatishchev
abatishchev

Reputation: 100308

string allText = WebBrowser1.DocumentText;

will return you all currently laoded document markup. Is it what are you lookin for?

Upvotes: 0

Blatfrig
Blatfrig

Reputation: 591

OK this feels like a dirty hack, but it solves my problem:

WebBrowser1.Document.ExecCommand("SelectAll", false, null);
WebBrowser1.Document.ExecCommand("Copy", false, null);`

Upvotes: 4

Sawyer
Sawyer

Reputation: 51

Another option would be to capture an image of the page, rather than the html and paste that into the document. I don't think the WebBrowser control can handle this, but Watin can. Watin's (http://watin.sourceforge.net/) capturewebpagetofile() function works well for this functionality. I have had to use this instead of capturing HTML because outlook cannot format HTML well at all.

Upvotes: 0

Jon Egerton
Jon Egerton

Reputation: 41569

I guess that happens because what the webbrowser actually contains is the markup, not all the images etc.

You might be best to use the webbrowser to save the full page to disk, and then use word to open that. That way it'll all be available locally for IE to use. Just means you have to clean up afterwards though.

The link below has some stuff about saving using the webbrowser in c#

http://www.c-sharpcorner.com/UploadFile/mahesh/WebBrowserInCS12072005232330PM/WebBrowserInCS.aspx

Upvotes: -1

Related Questions