Solved

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

Posted on 2004-04-02
5
286 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JS does not refresh 6 42
I need to Integrate Hubspot into my .asp application but don't know how to POST 11 53
Html split(text) 2 48
isNaN issue on the Table input text 2 41
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

734 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