View Full Version : Capture ASP to HTML code from Server

10-20-2003, 06:56 AM
Is there anyway to take the generated ASP code and save it? I have a dynamically created order form which also needs to be sent in an email(html).

I found this, but can't get it to work at all.


Thanks, Carini

10-20-2003, 08:59 AM
Welcome here. I'm not sure i understand what you try to do. If you want to reuse asp-code, then the easiest thing to do is save it in a seperate file and (with file-extensions .asp) and then use a server side include (SSI) to include it in the files you want to use it in.

<!--#include file='reusecode.asp'-->

Where reusecode.asp contains the asp-code you want to reuse. Like

10-20-2003, 01:07 PM
Use Microsoft's XMLHTTP Object (http://www.4guysfromrolla.com/webtech/110100-1.shtml)

10-20-2003, 06:26 PM
Raf - Sorry I wasn't too clear. I was wondering if you can capture the generated ASP page(HTML) that the server sends to the client. Just like if you were the client, and did a "Save As" of the webpage. I have a dynamic form, which I also need to send as a html email. So I just wanted to take the table the form produces, and send it via email.

Glenn, thanks for the link, I'll try that, but I just hope it's already installed on the server because I have no control over it.


10-20-2003, 10:04 PM
What you sent to the client is straight html.

The easies and most efficient way is instead of response.writing it or going out of asp mode like
some aspcode
some html
<%some asp %>

, you just stay is ASP-mode and add all the html you also want to mail to a stringvariable. And at the end of the page you have one variable whith all the html code in. Then you can do one response.write + use the variable as the emails body.

So you'de have stuff like

dim output
output="<table ...><tr>..."
output= output & "<td>...</td>..."
output= output & "The rest..."
... your mailcode

Instead of

response.write("<table ...><tr>...")

10-21-2003, 03:41 AM
hehe thanks raf!!! that worked perfectly, i guess I was trying to be lazy and not type everything out. I'm fairly new to asp, and didn't now if there was some kind of server command to call for the generated html


10-21-2003, 09:06 AM
I don't know of a servercommand to do that.

Maybe you can work something out by caching the output on a proxyserver and then reading that or so, but i don't have aclue how to do that.
You can also buffer the outpu while the script is executed, but i never saw a method to store the buffer-content in a variale + then you have all output (also the html header etc)

Just storing all or part of the output in a variable is easy, flexible, clean and efficient ...

10-21-2003, 11:03 AM
Originally posted by Carini
Glenn, thanks for the link, I'll try that, but I just hope it's already installed on the server because I have no control over it.

As mentioned by 4guysfromrolla, you need MSXML installed in the server. If the server has at least IE5 browser, it has MSXML installed. But you can download it in the link they provided.
Here's the sample code they showed. I modified it a bit for your needs:

Response.Buffer = True
Dim objXMLHTTP, xml, emailBody

' Create an xmlhttp object:
Set xml = Server.CreateObject("Microsoft.XMLHTTP")
' Or, for version 3.0 of XMLHTTP, use:
' Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP")

' Opens the connection to the remote server.
xml.Open "GET", "http://mydomain.com/somepage.asp", False

' Actually Sends the request and returns the data:

emailBody = xml.responseText

Set xml = Nothing

'send emailBody in email here


10-22-2003, 06:24 AM
That's some pretty cool **** Glenn.

P.S. In this post, "****" means "code". ;)

10-22-2003, 08:41 AM
I have basically the same script but with some error-checking:

<%@LANGUAGE="VBScript", EnableSessionState = False %>
Option Explicit
Response.Buffer = False

Function GrabPage(strURL)
Dim objXML
Set objXML = Server.CreateObject("Microsoft.XMLHTTP")
objXML.Open "GET", strURL, False

If Err.Number = 0 Then
If objXML.Status = 200 then
GrabPage = objXML.ResponseText
GrabPage = "Incorrect URL"
End if
GrabPage = Err.Description
End If

Set objXML = Nothing
End Function

Then to write the contents on a page, you simply include this:

<% response.write(GrabPage("http://www.bleh.zz/")) %>
<% myVariable = GrabPage("http://www.bleh.zz/") %>