include file according to a parameter

L

lucky

Hi

I need to include a file within a page but the address of the included
file depends on a parameter

So I wrote something like this:


<!--#include virtual="/<%=FolderName%>/includes/includefile.asp"-->
where FolderName is a variable containing a string.

But this doesn't work. It seems that you can't build an include link
with ASP.
And I can't test the value of my variable since I will have many
possible values and some new ones will be added regularly.

Is there a way to do this?

many thanks

Luc
 
L

lucky

I also tried this:


DIM filespec, fs, f, content
filespec = Server.MapPath("/" & FolderName & "/logos.asp")
set fs = CreateObject("Scripting.FileSystemObject")
set f = fs.OpenTextFile(filespec)
content = f.ReadAll()
set f = nothing
set fs = nothing

Response.Write(content)

But the ASP code in then displayed as plain text.
 
A

Anthony Jones

lucky said:
Hi

I need to include a file within a page but the address of the included
file depends on a parameter

So I wrote something like this:


<!--#include virtual="/<%=FolderName%>/includes/includefile.asp"-->
where FolderName is a variable containing a string.

But this doesn't work. It seems that you can't build an include link
with ASP.
And I can't test the value of my variable since I will have many
possible values and some new ones will be added regularly.

Is there a way to do this?

No. Can you rearrange things so that instead of using an include you can
use a Server.Execute?
 
A

Aaron Bertrand [SQL Server MVP]

I need to include a file within a page but the address of the included
file depends on a parameter

So I wrote something like this:


<!--#include virtual="/<%=FolderName%>/includes/includefile.asp"-->

This does not work, because the <!--#include directive is processed BEFORE
any code in <%%>.

http://www.aspfaq.com/2042
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top