Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Dynamic Server Side Include

I want to do a server side include on a page
where the file name which is to be included is
stored in a variable.

I tried to do this:



but it didn't work.

As you can see, the file name is stored in a variable
named fileName. The file is stored in a directory called
INCFiles

Does anyone know how to do this kind of SSI?

Thanks for lookin'
Allan

Comments

  • StPatrickStPatrick Member Posts: 76
    You can't do it with SSI, it is just no dynamic. Use Server.Execute(filename) instead

    [b][italic]Philip Patrick[/italic][/b]
    [b]Home page[/b]: http://www.saintopatrick.com
    [size=1][italic]"Two beer or not two beer?"[/italic] [b]Shakesbeer[/b][/size]

  • bagles1bagles1 Member Posts: 54
    To the best of my knowledge it can't be done that way (I gave it a quick shot myself and couldn't get it to work). However, when we are looking to do dynamic includes we wrap them in ASP "IF" statements, like this;
    <% If condition Then %>

    <% else %>

    <% end if %>

    -Bagles1

    : I want to do a server side include on a page
    : where the file name which is to be included is
    : stored in a variable.
    :
    : I tried to do this:
    :
    :
    :
    : but it didn't work.
    :
    : As you can see, the file name is stored in a variable
    : named fileName. The file is stored in a directory called
    : INCFiles
    :
    : Does anyone know how to do this kind of SSI?
    :
    : Thanks for lookin'
    : Allan
    :

  • aflat362aflat362 Member Posts: 50
    Thanks for the try,
    But this technique isn't going to work,
    my include files all have uniquely generated
    file names and I wouldn't be able to hard code them in any
    form. All I have is the File Name of the
    one I want to include in a variable.

    If I cannot do an "include" of the file,
    perhaps I could open the file, select all,
    copy, and Write it to my ASP page.

    Does anyone think this is a good idea? or know if this is
    even possible? or maybe you know a way to do what I referred to before
    as a "dynamic" SSI?

    : To the best of my knowledge it can't be done that way (I gave it a quick shot myself and couldn't get it to work). However, when we are looking to do dynamic includes we wrap them in ASP "IF" statements, like this;
    : <% If condition Then %>
    :
    : <% else %>
    :
    : <% end if %>
    :
    : -Bagles1
    :
    : : I want to do a server side include on a page
    : : where the file name which is to be included is
    : : stored in a variable.
    : :
    : : I tried to do this:
    : :
    : :
    : :
    : : but it didn't work.
    : :
    : : As you can see, the file name is stored in a variable
    : : named fileName. The file is stored in a directory called
    : : INCFiles
    : :
    : : Does anyone know how to do this kind of SSI?
    : :
    : : Thanks for lookin'
    : : Allan
    : :
    :
    :

  • aflat362aflat362 Member Posts: 50
    What would Server.Execute(fileName) do?
    does it pull the contents of the file into the ASP document
    like a #include statement does?

    : You can't do it with SSI, it is just no dynamic. Use Server.Execute(filename) instead
    :
    : [b][italic]Philip Patrick[/italic][/b]
    : [b]Home page[/b]: http://www.saintopatrick.com
    : [size=1][italic]"Two beer or not two beer?"[/italic] [b]Shakesbeer[/b][/size]
    :
    :

  • StPatrickStPatrick Member Posts: 76
    It executes the contest of the file. You need to figure out what the difference between include and Execute in your case. It is like a call of subroutine, but here the sub is a whole file. But all variables in the parent file are accessable in the child, though I'm not sure if otherwise is true.
    And you have to have IIS5 at least, as I remember this function is not present in IIS4

    : What would Server.Execute(fileName) do?
    : does it pull the contents of the file into the ASP document
    : like a #include statement does?
    :


    [b][italic]Philip Patrick[/italic][/b]
    [b]Home page[/b]: http://www.saintopatrick.com
    [size=1][italic]"Two beer or not two beer?"[/italic] [b]Shakesbeer[/b][/size]

  • bagles1bagles1 Member Posts: 54
    Well, I am not really sure what it is you are trying to do, but here is an idea from something I once did. If you are pulling file names from a directory (assuming that is what it is), you could loop through all the files using the filesystem object and then create one final file called "includes". You would create this file to build an ASP include file with the "IF" statements. This is possible and actually works very well. In essence if you have a page that creates a text file and then another page that displays that newly created file, then here is how it works.

    The page that creates the file, 1) creates the new file 2) then loops through the files in that directory and creates/overwrites another file, the "includes" file and builds the page with a select case statement. This should work because somewhere down the line you would have to either pass in the file name or know what it is ahead of time. I seriously doubt that the file is randomly generated for creation and execution as the odds of running across a randomly generated file are astronomical. Anyway... on the page that then displays the file you only have to include 1 and that is the "includes" file. Hopefully this makes sense to ya but I know this works. Best of luck!

    -Bagles1


    : Thanks for the try,
    : But this technique isn't going to work,
    : my include files all have uniquely generated
    : file names and I wouldn't be able to hard code them in any
    : form. All I have is the File Name of the
    : one I want to include in a variable.
    :
    : If I cannot do an "include" of the file,
    : perhaps I could open the file, select all,
    : copy, and Write it to my ASP page.
    :
    : Does anyone think this is a good idea? or know if this is
    : even possible? or maybe you know a way to do what I referred to before
    : as a "dynamic" SSI?
    :
    : : To the best of my knowledge it can't be done that way (I gave it a quick shot myself and couldn't get it to work). However, when we are looking to do dynamic includes we wrap them in ASP "IF" statements, like this;
    : : <% If condition Then %>
    : :
    : : <% else %>
    : :
    : : <% end if %>
    : :
    : : -Bagles1
    : :
    : : : I want to do a server side include on a page
    : : : where the file name which is to be included is
    : : : stored in a variable.
    : : :
    : : : I tried to do this:
    : : :
    : : :
    : : :
    : : : but it didn't work.
    : : :
    : : : As you can see, the file name is stored in a variable
    : : : named fileName. The file is stored in a directory called
    : : : INCFiles
    : : :
    : : : Does anyone know how to do this kind of SSI?
    : : :
    : : : Thanks for lookin'
    : : : Allan
    : : :
    : :
    : :
    :
    :

  • aflat362aflat362 Member Posts: 50
    perhaps we have gotten off track.
    let me re-explain my problem.

    there are a bunch of files in a directory called "INCFiles".
    these files each hold some HTML display content, like text or whatever.
    I need to Include one of the files into my ASP page for display, not execution.
    I have the file name of the one that I need to include stored in
    an asp variable named fileName.
    my first idea was to do the following:


    but this does not work because the include statement is executed (or attempted) before the fileName is appended to its path.

    if you have never run into a situation like this before, its fine, I'll probably find a work-around sooner or later, but thanks for helping to try and figure it out so far!


    : It executes the contest of the file. You need to figure out what the difference between include and Execute in your case. It is like a call of subroutine, but here the sub is a whole file. But all variables in the parent file are accessable in the child, though I'm not sure if otherwise is true.
    : And you have to have IIS5 at least, as I remember this function is not present in IIS4
    :
    : : What would Server.Execute(fileName) do?
    : : does it pull the contents of the file into the ASP document
    : : like a #include statement does?
    : :
    :
    :
    : [b][italic]Philip Patrick[/italic][/b]
    : [b]Home page[/b]: http://www.saintopatrick.com
    : [size=1][italic]"Two beer or not two beer?"[/italic] [b]Shakesbeer[/b][/size]
    :
    :

  • Shawn CarterShawn Carter Member Posts: 0

    _______ { http://forcoder.org } free video tutorials and ebooks about \ JavaScript, Go, Java, Ruby, R, C++, Scratch, PHP, C#, Python, PL/SQL, Objective-C, Swift, Assembly, Delphi, Visual Basic, Perl, C, MATLAB, Visual Basic .NET Crystal, Lisp, Clojure, VBScript, LabVIEW, Hack, Alice, Apex, SAS, Bash, Scala, FoxPro, Prolog, F#, D, Transact-SQL, ABAP, Logo, Awk, Julia, Scheme, ML, Ada, Lua, Rust, COBOL, Dart, Fortran, Erlang, Kotlin \ _____________

Sign In or Register to comment.