[RESOLVED] [2005] How to save HtmlDocument to a file???-VBForums
Results 1 to 6 of 6

Thread: [RESOLVED] [2005] How to save HtmlDocument to a file???

  1. #1

    Thread Starter
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,292

    Resolved [RESOLVED] [2005] How to save HtmlDocument to a file???

    Hi all,
    I'm using a WebBrowser control to download webpages and HtmlDocument to edit the Document. Once I'm done editing, how do I save the document to a html file? I just need guides and not the actual code since I do have the habit of copying and pasting.... And once I do that, I won't learn anything

  2. #2
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: [2005] How to save HtmlDocument to a file???

    I have never done this but can't you use a StreamWriter class to write the text context to a file with .html extension. For example
    VB Code:
    1. Dim f As New System.IO.StreamWriter(My.Computer.FileSystem.SpecialDirectories.Desktop & "\test.html")
    2.         f.Write(Me.WebBrowser1.DocumentText)
    3.         f.Close()

  3. #3

    Thread Starter
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,292

    Re: [2005] How to save HtmlDocument to a file???

    Yeah, that was the 1st thing I tried... However, DocumentText property returns the original html text, so it doesn't save the changes in the edited document.

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    97,409

    Re: [2005] How to save HtmlDocument to a file???

    The HtmlDocument class has an All property that returns an HtmlElementCollection. I'm guessing that you could get the HtmlElement from that that corresponds to the <HTML> tag. The InnerHtml property of that object would give a string containing all the HTML code within the <HTML> tag.

    Alternatively, you may be able to get the entire contents from its DomDocument property, which returns a refernce to an unmanaged object. Read the help topic for that property for more information.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,292

    Re: [RESOLVED] [2005] How to save HtmlDocument to a file???

    Thanks Jmc for pointing me in the dright direction... In case someone needs to do the same thing, WebBrowser1.Document.All(0).OuterHtml returns the whole document's html code as a string. Then I just use a streamwriter to write it to a file
    VB Code:
    1. Dim sw As New IO.StreamWriter(strFilePath, False)
    2.         sw.Write(WebBrowser1.Document.All(0).OuterHtml)
    3.         sw.Close()

  6. #6
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    97,409

    Re: [RESOLVED] [2005] How to save HtmlDocument to a file???

    Gee, who'd have thought that if there was an InnerHtml property that there'd be an OuterHtml property too? D'oh!
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.