Solved

Including a file in ASP

Posted on 2002-04-22
7
220 Views
Last Modified: 2013-11-18
Hi all...

I'm making a website in ASP (I used to work with PHP, in PHP the solution for my problem is the INCLUDE(filename) function) and I have a problem.

I want to insert the text of an other file into a ASP page.

i.e.:

index.asp
---------
<!--#include file="read.function.asp"-->
<html>
<head></head>
<body>
<%
strMenu = "create.asp"
Response.Write(ReadDisplayFile(strMenu) %>
</body>
</html>

This is the code of read.function.asp

read.function.asp
-----------------
<%
     Function ReadDisplayFile(FileToRead)
          strFileToRead = Server.Mappath(FileToRead)
          Set fs = CreateObject("Scripting.FileSystemObject")
          Set strThisFile = fs.OpenTextFile(strFileToRead, 1, False, TristateMixed)
          strTemp = strThisFile.ReadAll
          strThisFile.Close
          set strThisFile = nothing
          set fs = nothing
          ReadDisplayFile = strTemp
     end Function
%>

This is the code of create.asp

create.asp
----------
<html>
<head></head>
<body>
<form method="post" action="index.asp">
 <table>
  <tr>
   <td>Name:</td>
   <td><input type="text" name="first_name"></td>
  </tr>
 </table>
</form>
<% Response.Write("test") %>
</body>
</html>

Now, if I load index.asp in my browser...I see the form, but not the printout of <% Response.Write("test") %>.
So, the ASP-code is not parsed.

I also tried this
<% testje = """test.asp""" %>
<% Response.Write("<!--#include file="& testje & "-->") %>

but the include file-statement doesn't work when I use a variable...

Does anybody have a solution? I need this so bad...thank you very very much if you can help me...

Thanks...
0
Comment
Question by:RoB
7 Comments
 
LVL 19

Expert Comment

by:webwoman
ID: 6960115
You can't use a variable. Includes are done before the ASP is parsed, so there's no variable to use.

The include should definitely parse correctly, make sure that it's in the same directory as the main file. Also, you might want to rename it -- take out the . in the filename. I suspect that may be causing problems.
0
 
LVL 5

Expert Comment

by:harwantgrewal
ID: 6960121
is your asp is working I mean check the source of the page it display the asp tag that means your ASP is not parsing check iis

harry
0
 
LVL 7

Expert Comment

by:daniel_c
ID: 6960181
Just curious, why do you have to read the file?
Why don't just redirect to the ASP file?

Change this to your index.asp file:

<!--#include file="read.function.asp"-->
<html>
<head></head>
<body>
<%
strMenu = "create.asp"
Response.Redirect strMenu
'Response.Write(ReadDisplayFile(strMenu))
%>
</body>
</html>

HTH,

^_^
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 6

Expert Comment

by:ebosscher
ID: 6960239
I'm willing to hazard a guess.

The browser will not see the ASP as ASP because it is output, you are sending the new page directly to the browser window, the browser is not calling the ASP through IIS, and so IIS sees no need to parse the page it is receiving.  I could be wrong, but that SEEMS like what it is doing.

I would suggest not streaming pages that require interpritation by the server, the server probably sees these as a text stream, and not as an ASP.

Regards,

Evan
0
 
LVL 11

Accepted Solution

by:
ASPGuru earned 60 total points
ID: 6960527
hi RoB,

if you have Win2k you can use:
Server.Execute testje

ASPGuru
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 6960604
try this:

testje MUST be a fully qualified URL: http://server/path/file.inc

<%
 Response.Buffer = True

 RePost(testje)  'note: this must be a fully qualified URL

 Function RePost( postURL )  'instead of redirecting, repost the form data

   Dim objXMLHTTP, xml
   Set xml = Server.CreateObject("Microsoft.XMLHTTP")
   xml.Open "POST", postURL, False
   xml.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
   xml.Send "" & Request.Form &"&"& Request.QueryString &"&"& Request.Cookies
   Response.Write xml.responseText
   'RePost = ""&xml.responseText
   Set xml = Nothing

 End Function
%>
0
 

Author Comment

by:RoB
ID: 6960778
Thank you very much mate...

RoB
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
JQuery Date Time picker not showing 29 92
Question on web subscription for apps 3 73
API Soap Calls 4 56
Problem to Popup 2 48
There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

707 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

14 Experts available now in Live!

Get 1:1 Help Now