Including a file in ASP

Posted on 2002-04-22
Medium Priority
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.


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

This is the code of 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
          set strThisFile = nothing
          set fs = nothing
          ReadDisplayFile = strTemp
     end Function

This is the code of create.asp

<form method="post" action="index.asp">
   <td><input type="text" name="first_name"></td>
<% Response.Write("test") %>

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...

Question by:RoB
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
LVL 19

Expert Comment

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.

Expert Comment

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


Expert Comment

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"-->
strMenu = "create.asp"
Response.Redirect strMenu


WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.


Expert Comment

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.


LVL 11

Accepted Solution

ASPGuru earned 240 total points
ID: 6960527
hi RoB,

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

LVL 33

Expert Comment

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

Author Comment

ID: 6960778
Thank you very much mate...


Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Suggested Courses

800 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