|
|
 |
Dynamic Include Problem
FreshMagic | Posted 2:16pm 3. December 2003 Server Time |
Yea, on my site I'm using a dynamic include, but the problem is that I want it to actually run the asp script in the included page when being included, rather than just displaying it as text.
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
The dynamic include looks like this:
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objText = objFSO.OpenTextFile(Server.MapPath("../files/" & ID & ".asp"))
Content = objText.ReadAll
objText.Close
Set objText = Nothing Set objFSO = Nothing
response.write Content
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Any ideas?
|
mp3cdman | Posted 2:44pm 3. December 2003 Server Time |
Server.Execute possibly??
it all depends what is actually in the include file...
mp3cdman ;-)
FreshMagic | Posted 3:12pm 3. December 2003 Server Time |
asp, stuff like database connections and so on.
thorpe | Posted 5:54am 4. December 2003 Server Time |
it should run, and definately shouldnt just diplay as text.
whay extension has your include got? if you want it too execute as asp, you must give it the .asp exension.
FreshMagic | Posted 11:41am 4. December 2003 Server Time |
No, I'm absolutely possitive it's not executing any asp commands, and it is an asp file. The dynamic include only reads the file's text and prints it out, not executing it whatsoever. Looking at the html I can see the asp command written, and not executed.
Could someone please find a way I could solve this problem, perhaps another method for dynamic include? Thanks still for trying guys.
rmfred | Posted 12:25am 4. December 2003 Server Time |
This is from Asp101... might get you going <%
'Pass the name of the file to the function. Function getFileContents(strIncludeFile) Dim objFSO Dim objText Dim strPage
'Instantiate the FileSystemObject Object. Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
'Open the file and pass it to a TextStream Object (objText). The '"MapPath" function of the Server Object is used to get the 'physical path for the file. Set objText = objFSO.OpenTextFile(Server.MapPath(strIncludeFile))
'Read and return the contents of the file as a string. getFileContents = objText.ReadAll
objText.Close Set objText = Nothing Set objFSO = Nothing End Function %>
FreshMagic | Posted 3:19pm 4. December 2003 Server Time |
Okay, I appreciate all of you trying to help, but you don't seem to quite understand the problem. At the momment I'm using the dynamic include that rmfred demostrates above (I'm using dynamic include since the filenames of the files being included aren't predetermined), however, it simply opens the file, reads the contents and then writes it. Here is the problem I have: being a dynamic include which simple reads and displays, it doesn't run the asp scripts contained on the dynamicaly included pages, rather, it simple displays the code as text,
eg. as a test I typed <%response.write("Hello!")%> on one of the included pages, and normally with asp it would simply display 'Hello!', but when included using the dynamic include, the source countained '<%response.write("Hello!")%>'.
The thing is that I require a way of having dynamic include which also runs the asp script on the included pages.
Does anyone know a way of does this?
thorpe | Posted 5:41pm 4. December 2003 Server Time |
the method above to me looks like it is performing correctly. its not meant to execute the file, just simply display it. it sends the file to the 'text stream' which bassically just prints it to the screen.
if you want to include an asp file use <!-- #include file="yourfile.asp" -->
i have read somewhere that you cant include 'dynamic' includes this way though
eg;
<!-- #include file=" & incude & "-->
but i have also read that there is a work around. maybe this is what your looking for?
mp3cdman | Posted 8:59am 5. December 2003 Server Time |
look guys,
Dynamic Includes using OpenTextFile will not execute and asp code which is present in the file.
You can use Server.Execute or Server.Transfer to eexcute other code files and these can take parameters and variables.... thus can be dynamic...
you can simulate these by making use of the Execute function in ASP see this
http://www.4guysfromrolla.com/webtech/042602-1.shtml
mp3cdman ;-)
greyknght1 | Posted 9:29am 5. December 2003 Server Time |
Open the file, create a new file with an asp extension, then include it on your page somewhere. Server.Execute makes more sense though.
Greyknght1 Mike
FreshMagic | Posted 7:36am 6. December 2003 Server Time |
Hey, thanks for all the help guys, especially mp3cdman, I'm going to use that method. Thanx so much people! ;D
Show all replies to 'Dynamic Include Problem'
|
This post have been closed for new replies
|
|
|
|
 |
|