Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Senior Coder
    Join Date
    May 2004
    Posts
    1,457
    Thanks
    15
    Thanked 0 Times in 0 Posts

    save a web page as file

    Is there anyway in asp that I can pull up a url(of an asp page) and save it as an html file on my server.

  • #2
    Senior Coder
    Join Date
    Apr 2003
    Location
    England
    Posts
    1,192
    Thanks
    5
    Thanked 13 Times in 13 Posts
    this allows you to post data so the target site cna read it as request.form if needed (urlencoded)
    Code:
    Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
    
    objXmlHttp.Open "POST", "http://www.domain.com/page.asp", False
    objXmlHttp.SetRequestHeader "Content-type", "application/x-www-form-urlencoded"
    objXmlHttp.Send ""
    
    If objXmlHttp.Status = 200 Then
    	strHTML = objXmlHttp.ResponseText
    End If
    Set objXmlHttp = Nothing
    once you have the generated html in a string use fso to save it as a file (see asp/fso references in my signature)

  • #3
    Senior Coder
    Join Date
    May 2004
    Posts
    1,457
    Thanks
    15
    Thanked 0 Times in 0 Posts
    so this code goes in which file? The one that is outputted (and I want to save) or do I use this code when trying to save the url?

    thanks

  • #4
    Senior Coder
    Join Date
    Apr 2003
    Location
    England
    Posts
    1,192
    Thanks
    5
    Thanked 13 Times in 13 Posts
    xmlhttp is used by the server to request http data (usually xml but in this case html, makes no real diff) from an external webserver. you can then use the html it has collected to do with as you wish, in this case i would just save it to a string, close the xmlhttp object and save it to a html file with the file system object (fso) provided you have write permissions of course.

    for example if you save this string to a file called website.html you can then go to it as if it were a html file on your server. this code must of course be in an asp file.

    you could also use
    Code:
    Response.ContentType = "text/html"
    Response.BinaryWrite strHTML
    to make the asp page just appear to the browser as a download that you can click open/save on (i think)

  • #5
    Senior Coder
    Join Date
    May 2004
    Posts
    1,457
    Thanks
    15
    Thanked 0 Times in 0 Posts
    not sure if this is what I need.

    let me explain further.

    I have an invoice that is generated from asp -- not it's a combination of asp and html.

    I want to be able to put a button -- to email the invoice as an attachment -- but am trying to see if I can save all the work of converting the html to a string (all the quotes in it etc...)

    any suggestions? Will the above help me?

  • #6
    Senior Coder
    Join Date
    Apr 2003
    Location
    England
    Posts
    1,192
    Thanks
    5
    Thanked 13 Times in 13 Posts
    its not expanding the question if you ask a totally different one

    you could use xmlhttp to get the html from a diff file into a string but ur not sposed to use it on the same server (or at least virtural directory)

    i doubt theres a way to flush out everythign in the response buffer into a string so you will probably have to use a string anyway, its not too hard just use your editor to find and replace "Response.Write" with "strOutput = strOutput &"

    and put strOutput atthe start (dim if you need to, otherwise just start with strOutput = "") then use cdonts/cdosys to add the attachment with a contenttype and just use that string as the attachment.
    Last edited by ghell; 08-08-2005 at 12:07 PM.


  •  

    Posting Permissions

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