Results 1 to 8 of 8

Thread: Including a file dynamically

  1. #1

    Thread Starter
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845

    Including a file dynamically

    I expect this has been asked 26.4 times already but...

    I am passing a page name to an ASP in the request string. I want to then include it using <!-- #include file='filename' -->

    (fName is the variable holding the page name)

    if I do<%
    response.write "<!-- #include file='" & fName & "' -->"%>

    the include string gets written correctly but the page doesn't get included.

    if I do
    <!-- #include file='<%=fName%>'-->



    it says can find file <%=fName%>
    Mark
    -------------------

  2. #2
    Fanatic Member Jerry Grant's Avatar
    Join Date
    Jul 2000
    Location
    Dorset, UK
    Posts
    810
    Try:
    <!-- #include file='<%=Request.QueryString("fName")%>'-->
    Jerry Grant................tnarG yrreJ
    Website: <JG-Design></.net>
    Email: [email protected]
    Working towards a bug free world......
    (Not a Microsoft employee)

  3. #3

    Thread Starter
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845

    Unhappy

    Nope!
    That doesn't work either

    thanks
    Mark
    -------------------

  4. #4
    Lively Member
    Join Date
    Aug 2000
    Location
    South Africa
    Posts
    113

    why double quotes?

    how come u using double quotes?
    You are living a pacifist dream, and if you dreaming it means you sleeping and you should damn well wake up!

  5. #5
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    The include gets processed before the page gets sent to the ASP engine, that's why its not working. I did a quick search on some asp sites, but I didn't see an exact workaround to what you need. You could use includes in if statements outside of the asp tags, but that causes all includes to be inserted.
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  6. #6

    Thread Starter
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    I figured that was the problem.

    What I've done now is include a seperate asp file with a select statment in to write out the correct include string
    Mark
    -------------------

  7. #7
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Try including all files that you may need.

    EDIT \/
    ..eh What? Oh, you've solved your problem.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  8. #8
    Lively Member
    Join Date
    Jan 2001
    Posts
    72
    JoshT is right, 'includes' gets parsed before ASP. If you want true 'dynamic includes', you wouldn't even use the #include statement. You'd have to use the filesystem object, read the contents of a file, then spit it out. I've made a template using it that way. There's an article on www.asp101.com about this topic. Just search it on their site.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width