Solved

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

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

630 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