Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-04-02
5
Medium Priority
?
294 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 100 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 100 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
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/…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

688 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