View Full Version : save a web page as file

08-08-2005, 12:18 PM
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.

08-08-2005, 12:33 PM
this allows you to post data so the target site cna read it as request.form if needed (urlencoded)
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 = Nothingonce you have the generated html in a string use fso to save it as a file (see asp/fso references in my signature)

08-08-2005, 12:36 PM
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?


08-08-2005, 12:42 PM
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
Response.ContentType = "text/html"
Response.BinaryWrite strHTMLto make the asp page just appear to the browser as a download that you can click open/save on (i think)

08-08-2005, 12:45 PM
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?

08-08-2005, 12:57 PM
its not expanding the question if you ask a totally different one :rolleyes:

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.