Go Back   CodingForums.com > :: Server side development > ASP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-08-2005, 11:18 AM   PM User | #1
esthera
Senior Coder

 
Join Date: May 2004
Posts: 1,432
Thanks: 14
Thanked 0 Times in 0 Posts
esthera can only hope to improve
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.
esthera is offline   Reply With Quote
Old 08-08-2005, 11:33 AM   PM User | #2
ghell
Senior Coder

 
Join Date: Apr 2003
Location: England
Posts: 1,192
Thanks: 5
Thanked 13 Times in 13 Posts
ghell is on a distinguished road
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)
__________________
My tech/code blog
ghell is offline   Reply With Quote
Old 08-08-2005, 11:36 AM   PM User | #3
esthera
Senior Coder

 
Join Date: May 2004
Posts: 1,432
Thanks: 14
Thanked 0 Times in 0 Posts
esthera can only hope to improve
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
esthera is offline   Reply With Quote
Old 08-08-2005, 11:42 AM   PM User | #4
ghell
Senior Coder

 
Join Date: Apr 2003
Location: England
Posts: 1,192
Thanks: 5
Thanked 13 Times in 13 Posts
ghell is on a distinguished road
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)
__________________
My tech/code blog
ghell is offline   Reply With Quote
Old 08-08-2005, 11:45 AM   PM User | #5
esthera
Senior Coder

 
Join Date: May 2004
Posts: 1,432
Thanks: 14
Thanked 0 Times in 0 Posts
esthera can only hope to improve
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?
esthera is offline   Reply With Quote
Old 08-08-2005, 11:57 AM   PM User | #6
ghell
Senior Coder

 
Join Date: Apr 2003
Location: England
Posts: 1,192
Thanks: 5
Thanked 13 Times in 13 Posts
ghell is on a distinguished road
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.
__________________
My tech/code blog

Last edited by ghell; 08-08-2005 at 12:07 PM..
ghell is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:25 PM.


Advertisement
Log in to turn off these ads.