0

I am not sure if WebBrowser.DocumentText contains only top document source or frames document text also included. Could not find that from MSDN page.

walter
  • 843
  • 2
  • 14
  • 35

1 Answers1

0

No it does not. I have tried next:

DocumentText:

File.WriteAllText(@"C:\doc.txt", webBrowser1.DocumentText, Encoding.UTF8);

GetElementsByTagName("HTML")

HtmlElement elem;
if (webBrowser1.Document != null)
{
    HtmlElementCollection elems = webBrowser1.Document.GetElementsByTagName("HTML");
    if (elems.Count == 1)
    {
        elem = elems[0];
        string pageSource = elem.OuterHtml;
        File.WriteAllText(@"C:\doc.txt", pageSource, Encoding.UTF8);
    }
}

IOleCommandTarget

public void ShowSource()
{
    IOleCommandTarget cmdt = null;
    object o = null;
    object oIE = null;
    try {
            cmdt = (IOleCommandTarget)this.Document.DomDocument;
            cmdt.Exec(cmdGUID, oCommands.ViewSource, 1, o, o);
    } catch (Exception ex) {
            throw new Exception(ex.Message.ToString(), ex.InnerException);
    } finally {
            cmdt = null;
    }
}

The only way is to go through all frame documents.

Updated If iframe has different url you will get UnauthorizedAccessException when trying to retrieve iframe document

Community
  • 1
  • 1
walter
  • 843
  • 2
  • 14
  • 35