include file according to a parameter

Discussion in 'ASP General' started by lucky, Jul 18, 2006.

  1. lucky

    lucky Guest

    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
     
    lucky, Jul 18, 2006
    #1
    1. Advertisements

  2. lucky

    lucky Guest

    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.
     
    lucky, Jul 18, 2006
    #2
    1. Advertisements

  3. No. Can you rearrange things so that instead of using an include you can
    use a Server.Execute?
     
    Anthony Jones, Jul 18, 2006
    #3
  4. I need to include a file within a page but the address of the included
    This does not work, because the <!--#include directive is processed BEFORE
    any code in <%%>.

    http://www.aspfaq.com/2042
     
    Aaron Bertrand [SQL Server MVP], Jul 18, 2006
    #4
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.