Solved

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

Posted on 2004-04-02
5
289 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

729 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