[RESOLVED] VB .Net Page save as an HTML.-VBForums
Results 1 to 7 of 7

Thread: [RESOLVED] VB .Net Page save as an HTML.

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2003
    Location
    Out there somewhere!
    Posts
    386

    Resolved [RESOLVED] VB .Net Page save as an HTML.

    Hello

    I was wondering if my Web application loads an vb.net page, once that page is loaded is it possible to save it as a HTML file automatically so that I can store it into a document store?


    Thanks

    Kev.

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,292

    Re: VB .Net Page save as an HTML.

    what is an "vb.net page"? Can you explain a little more on what you're trying to achieve?
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2003
    Location
    Out there somewhere!
    Posts
    386

    Re: VB .Net Page save as an HTML.

    Sorry. I'll try explain it better.

    In a web application I have a button that when selected it runs up an aspx file in a new browser window. It is this window that once loaded I want to be saved as an HTML file so that I can store in our document store.

    The asp code I used to run it as follows

    [code]
    <a target="_new" href="./MG09WitList.aspx?cid=##UNQ-ID##"><img alt="Create MG09 for Witnesses" border="0" src="" name="imgBtnCreateRec" style="display:inline" /></a>
    [\code]

    And the aspx file has a VB code file.

    Does that make more sense?

    Thanks

    Kev.

  4. #4
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,292

    Re: VB .Net Page save as an HTML.

    If you write a windows application using a webbrowser control, I believe you can.
    On the other hand, it appears that the new window open the page "./MG09WitList.aspx?cid=##UNQ-ID##", so you have control over the source code of the page. Can you modify it to save the page contents in Page.Load or Page.LoadComplete event of that page using Request.SaveAs() method?
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2003
    Location
    Out there somewhere!
    Posts
    386

    Re: VB .Net Page save as an HTML.

    I have put the following code -

    Code:
    Private Sub Page_LoadComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.LoadComplete
    
            Request.SaveAs("C:\Test.HTML", True)
    
        End Sub
    This saves the file fine, but when you open it gives me -

    GET /JUSTiS/MG09WitList.aspx?cid=1622 HTTP/1.1 Connection: Keep-Alive Accept: */* Accept-Encoding: gzip, deflate Accept-Language: en-gb Cookie: ASP.NET_SessionId=33m3mrb2fk4ltv2ilxk4s4an Host: localhost:2468 Referer: http://localhost:2468/JUSTiS/treeview.aspx User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)


    Unfortunately this is not what I want to save. I was wanting to save the source code.

    Any ideas?

    Thanks again

    Kev.

  6. #6
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,292

    Re: VB .Net Page save as an HTML.

    How about overriding the Page.Render method and save the page contents to a file there. Try this:
    Code:
    Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
            Dim txtWriter As System.IO.TextWriter = New System.IO.StringWriter()
            Dim htmlTxtWtr As New HtmlTextWriter(txtWriter)
            MyBase.Render(htmlTxtWtr)
            Dim htmlSource As String = txtWriter.ToString()
            Dim savePath As String = "D:\test.html"
            Using stremWtr As New System.IO.StreamWriter(savePath)
                stremWtr.Write(htmlSource)
            End Using
            writer.Write(htmlSource)
        End Sub
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2003
    Location
    Out there somewhere!
    Posts
    386

    Re: VB .Net Page save as an HTML.

    That worked.

    Thanks a lot, you've been a great help.


    Kev.

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.