Click to See Complete Forum and Search --> : Pass a Variable with Include File?


theflyingminst
03-19-2008, 05:28 PM
Hi I am trying to pass a folder name as a variable with include file. I've tried both of these idears and they return errors.

<!--#include file="../" & Your_UserName & "/default.asp"-->

<!--#include file="../<% =Your_UserName %>/default.asp"-->


Anyone got any idea's on this one?

Thanks.

.. Oh, also I shoouuld mention that I tried it this way and it shows the html of the page not the page results:

<%

cboFile=Request.QueryString("cboFile")
If MID(Request.QueryString("cboFile"),1,1)="/" Then
cboFile=MID(cboFile,2,LEN(cboFile))
End If

'And the page that joins everything together is:

'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
'-------------------------------------------------------------
'The "getFileContents" function should be included at the top
'of the ASP file.
'-------------------------------------------------------------
'Declare variables to hold the content of the main page and
'the include file.
Dim strMain, strInclude
'Get the contents of the main page and pass them to the "strMain"
'variable.
strMain = getFileContents("../" & Your_UserName & "/default.asp")
'Test to see if the "cboFile" select box is being submitted. If so,
'load the requested include file. If not, load the default include.
If Request.QueryString("cboFile") = "" Then
strInclude = getFileContents("maintemplate.asp")
Else
strInclude = getFileContents(cboFile)
End If
'After the proper include file contents are loaded ("strInclude"),
'then insert it into the main page ("strMain") using the "Replace"
'function.
strMain = replace(strMain,"<!-- INCLUDE FILE HERE -->",strInclude)
'Remove hyperlink formating inserted by Word
strMain = replace(strMain,"a:link, span.MsoHyperlink","")
strMain = replace(strMain,"{color:blue;", "")
strMain = replace(strMain,"text-decoration:underline;}", "")
strMain = replace(strMain,"a:visited, span.MsoHyperlinkFollowed", "")
'Use the "Response" Object to "Write" the completed page to the client.
Response.Write strMain


%>

jeremu
03-19-2008, 06:37 PM
They say it cannot be done, but I swear I have seen some configuration to make it work.
http://www.codefixer.com/tutorials/dynamic_includes.asp

Don't give up.

theflyingminst
03-19-2008, 06:44 PM
Thanks, I actually saw the link you attached. I just don't know how I would implement that in a a way to call a folder variable rather than a file one.

jeremu
03-19-2008, 06:49 PM
Could you do a XMLHTTP request to the include file and return the rendered HTML?

jeremu
03-19-2008, 06:53 PM
I picked this out of a script I wrote so I hope it complete, but I think it will show you the concept.

'XML Objects
Dim objHTTP, objXML, objList
Set objHTTP = Server.CreateObject("Microsoft.XMLHTTP")
Set objXML = Server.CreateObject("Microsoft.XMLDOM")
Set objList = Server.CreateObject("Microsoft.XMLDOM")

'HTTP String To Post to Include file
Dim strPostXML
strPostXML = "param=someParam"
objHTTP.open "POST", "http://www.domain.com/yourFolder/yourPage.asp", false
objHTTP.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
objHTTP.Send strPostXML

'Collect the XML of the response
Dim strResponseXML
strResponseXML = objHTTP.responseXML.xml


I think you can use the strResponseXML as your rendered asp page.

theflyingminst
03-19-2008, 08:42 PM
Great code! Thank you so much!

jeremu
03-21-2008, 01:25 PM
Let me know if this worked for you or if you found another solution.
I'm interested in knowing.

theflyingminst
03-21-2008, 01:36 PM
To be honest I had a hard time implementing it Jeremu. I appreciate you helping me out so much though.

What I ended up doing was making a frames page from where I wanted the include to go and including the page from there, basically I switched the targets around.

jeremu
03-21-2008, 02:04 PM
Did you use frames or iframes?

theflyingminst
03-21-2008, 02:42 PM
Just regular frames.

yamaharuss
03-21-2008, 07:24 PM
If possible, it would be easier to globally include your nav or other universal sections in each user's default page. (kinda backward from what you're doing now)

Then when a user logs on just use:

response.redirect("/"&Your_UserName&"/default.asp")

theflyingminst
03-21-2008, 08:02 PM
Daaaang, I didn't know you could do that?? Cool! Thanks Yamaharuss.