954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

WebBrowser Control - Saving Source

Hey, im just wondering how to say the source of a webpage that is in your WebBrowser Control.

I've tried loads of methods but i am failing horribly (google isnt my friend today). Just wondering if someone could share some insight :).

FTProtocol
Junior Poster
102 posts since May 2008
Reputation Points: -14
Solved Threads: 1
 
Aneesh_Argent
Junior Poster
104 posts since Dec 2008
Reputation Points: 16
Solved Threads: 18
 

Hope this will be helpful

http://support.microsoft.com/kb/329014

i already read through all that lol and i didn't understand :(

FTProtocol
Junior Poster
102 posts since May 2008
Reputation Points: -14
Solved Threads: 1
 
i already read through all that lol and i didn't understand :(


Even I dont understand the whole article:icon_rolleyes:
But U just need to do this:

Include references to the Mshtml.dll file . To do this in your Visual C# .NET project, follow these steps:

1. Click Add Reference on the Project menu.
2. Click the COM tab.
3. Double-click Microsoft HTML Object Library.

On your View Source button or menu Click do this:

mshtml.HTMLDocument objHtmlDoc = (mshtml.HTMLDocument) webBrowser1.Document.DomDocument;
/*webBrowser1 is the WebBrowser Control showing your page*/
string pageSource = objHtmlDoc.documentElement.innerHTML;

/* pageSource string variable will contain the source of the page displayed in your browser control. You can dispaly it in whatever way u wish to */
Aneesh_Argent
Junior Poster
104 posts since Dec 2008
Reputation Points: 16
Solved Threads: 18
 

In case Some One Else comes across this page; This is a much easy approach for beginners:

private void pageSourceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form sourceForm = new Form();
            TextBox sourceCode = new TextBox();
            sourceCode.Dock = DockStyle.Fill;
            sourceCode.Multiline = true;
            sourceCode.ScrollBars = ScrollBars.Both;
            sourceForm.Width = 700;
            sourceForm.Height = 500;
            sourceForm.StartPosition = FormStartPosition.CenterScreen;
            sourceForm.ShowIcon = false;
            sourceForm.ShowInTaskbar = false;
            sourceForm.Text = "Source Code for " + WebBrowser.Url;
            sourceCode.Text = WebBrowser.DocumentText;
            sourceForm.Controls.Add(sourceCode);
            sourceForm.Show(this);
            sourceCode.ReadOnly = true;
        }
saad749
Light Poster
45 posts since Sep 2010
Reputation Points: 10
Solved Threads: 5
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You