Solved

How can I execute asp code written by a response.write

Posted on 2004-04-02
5
273 Views
Last Modified: 2006-11-17
In order to make our web pages printable we use some asp code which reads the asp file off of the server and writes out the main content (uses comments to determine the main content start/end).  Our only problem is that occasionally we have asp within the main content - and though it gets written by our response.write statements, it's not executed.

Below is our printable.asp code:

<%
Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' PinterFriendly.asp
''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Prints a printer friendly version of page sent to it as query string
' Uses the Micro Focus Style Sheet
'
' Relies on the main content of the page being send being place between two HTML comment
' stings
' e.g.
'
'      <!-- Main Content -->
'
'      the HTML content would be in here...
'
'      <!-- End Main Content -->
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' 30Oct2001 MBW: Initial version
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''
sub OutputPageStart
      Response.Write "<html>"
      Response.Write "<head>"
      %>
      <!-- #include virtual="/_includes2/css/stylesheet.asp" -->
      <%
      Response.Write "</head>"
      Response.Write "<body bgcolor=""white"">"
      ' put in logo
end sub

sub OutputPageEnd
      ' !!!!!!!!!!!!!!!!!!!!!write copy right and date!!!!!!!!!!!!!!!!
      Response.Write "</body>"
      Response.Write "</html>"
end sub

Dim strFileURL, strFilePath, strQS
Dim oTools, oFS, oTextFile, strLine

set oTools = Server.CreateObject("MSWC.Tools")

strFileURL = Request.QueryString

'Response.Write "w" & strQS & "W" & "<br>"
'Response.Write oTools.FileExists("/index.asp") & "<br>"

If oTools.FileExists(strFileURL) = True Then
      ' file exists so
      'Response.Write "Found the file: " & strFileURL & "<br>"
      ' open file

      strFilePath = Server.MapPath(strFileURL)

      Set oFS = CreateObject("Scripting.FileSystemObject")
      Set oTextFile = oFS.OpenTextFile(strFilePath, 1, 0)

      ' output start of page
      Call OutputPageStart

      ' read to <!-- Main Content -->
      Do
            strLine = oTextFile.Readline
      Loop Until Instr(strLine, "<!-- Main Content -->") or oTextFile.AtEndOfStream

      If Instr(strLine, "<!-- Main Content -->") Then
            ' we found the start so start outputing content
            'Response.Write "found it!"
            ' output until reach <!-- End Main Content -->
            Do
                  strLine = oTextFile.Readline
                  Response.Write strLine
            Loop Until Instr(strLine, "<!-- End Main Content -->") or oTextFile.AtEndOfStream
      Else
            Response.Write "Unable to format for Printer Friendly mode"
      End If

      Call OutputPageStart

      ' clean up
      Set oTools = nothing

Else
      ' file does not exist
      Response.Write "Can't find the file"
End If

%>
0
Comment
Question by:mfwebteam
  • 2
5 Comments
 
LVL 4

Accepted Solution

by:
Danielcmorris earned 25 total points
ID: 10745371
Here's a function that I use on occasion.  It opens a page as if it were a user, displaying it the way it would look if the user opened it, causing the asp code to run.  I use it to send receipts to clients after a purchase.  I need the html from an asp page to put into the body of the email, so this has been great for me.

my_asp_file= receipt("printable_receipt.asp")
Response.Write my_asp_file

function receipt(mypage)
   Set srvXmlHttp = CreateObject("MSXML2.ServerXMLHTTP")
   srvXmlHttp.Open "GET", mypage, False, username, password
   srvXmlHttp.send()
   on error resume next
   if srvXmlHttp.status = 200 Then
           receipt = srvXmlHttp.responsetext
   else
            receipt="FAILED TO CREATE PAGE : ERROR 100"
   end if
   set srvXmlHttp=nothing
end function
0
 
LVL 4

Assisted Solution

by:anderson22
anderson22 earned 25 total points
ID: 10746289
Server.Execute("PageName.asp")

-rca
0
 
LVL 4

Expert Comment

by:Danielcmorris
ID: 10746551
Hmmm...  That'll probably do what you need.

0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now