ASP - Dynamically include HTML page in ASP page

Posted on 2012-09-15
Last Modified: 2012-09-15
I have an ASP page. In it I have a DIV and in that I want to include an Include file which is only HTML '' - (NNNN is obtained from a database according to a Query String. That part I can do and will be in this <% =rsData.Fields.Item("").Value %> )

I know I can't have a dynamic include file because the Include is processed before the <% %> script.

The file I want to include is an HTML file. ie. no script to run on it. (Each of these have an article relating to the topic NNNN. can be up to 1,000 words)

Can someone suggest any ideas please?

My present knowledge is classic ASP. If PHP or ASP.NET have a solution I'm listening.
Question by:hindersaliva
    LVL 58

    Accepted Solution

    How about
    Server.Execute(filename & ".html")

    Author Comment

    That simple. It worked!

    A point to make: My last ASP hard core was until 2002 working with ASP2. just now I read a lot of stuff dated pre-ASP3.0 (that's now out of date) tearing my hair out.

    I should have asked here first but wanted to put in some research before I did. Wasted 1.5 hours!
    Thanks Gary!
    LVL 58

    Expert Comment

    LVL 82

    Expert Comment

    by:Dave Baldwin
    Well, it took too long but here's my version that works off the query string.  You'd have to make up your own 'inc' files.
    <%@ LANGUAGE = VBScript %>
    <%  Option Explicit		%>
    dim fs,fnum,filnam,t,x
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    <title>ASP Read Text</title>
    <h1>ASP Read Text</h1>
    <h3>Test Links</h3>
    <a href="ASPreadtext.asp?fnum=1">ASPreadtext.asp?fnum=1</a><br>
    <a href="ASPreadtext.asp?fnum=2">ASPreadtext.asp?fnum=2</a><br>
    If fnum<>"" Then
    	filnam = "include" & fnum & ".inc"
    	set fs=Server.CreateObject("Scripting.FileSystemObject")
    	set t=fs.OpenTextFile(Server.MapPath(filnam), 1)
    End If

    Open in new window


    Author Comment

    I have already accepted Gary's solution. It works.

    Has Scripting.FileSystemObject have an advantage over Server.Execute?
    Thanks for doing it.
    LVL 82

    Expert Comment

    by:Dave Baldwin
    I know but I finished it so I posted it.
    Has Scripting.FileSystemObject have an advantage over Server.Execute?
    I have no idea.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
    Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    779 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

    15 Experts available now in Live!

    Get 1:1 Help Now