[thelist] Need Server-Side ASP script
Anthony Baratta
Anthony at Baratta.com
Mon Dec 1 20:06:02 CST 2003
At 04:36 PM 12/1/2003, Sam Carter wrote:
>I need to implement a server - side "include" function in ASP which will
>calculate a filename, then include the selected file into the HTML source
>code.
>
>Does anyone have a good example script that will read a specified file name
>and write it to the HTML output?
Here's some real olde code I had laying around...Watch for line wrap.
varIncludeFile = "default file"
varURLKey = "default key"
IncludeFile varIncludeFile,varURLKey
''''''''''''''''''''''''''''''''''''''''''''''''''
'' Read Include File Sub Routine
'' Required Info Passed to Function: (varIncludeFile,varURLKey)
'' varIncludeFile = File to Output to the Browser
'' varURLKey = URL Query Key to look for
''''''''''''''''''''''''''''''''''''''''''''''''''
SUB IncludeFile(varIncludeFile,varURLKey)
varTopicURI = ""
if (Request.QueryString.Count = 1) then
if not (lcase(Trim(Request.QueryString(varURLKey))) = "" OR _
isNull(lcase(Trim(Request.QueryString(varURLKey)))) ) then
varTopicURI = lcase(Trim(Request.QueryString(varURLKey)))
varIncludeFile = varTopicURI
end if
end if
varIncludeFile = varIncludeFile & ".inc"
Session("TopicURI") = varTopicURI
'' Stripping out possible ../../.. hacks
varForwardSlash = InStrRev(varIncludeFile,"/",-1,1)
varBackSlash = InStrRev(varIncludeFile,"\",-1,1)
if (varForwardSlash < varBackSlash) then
varIncludeFile = Right(varIncludeFile,(Len(varIncludeFile) -
varBackSlash))
elseif (varForwardSlash > varBackSlash) then
varIncludeFile = Right(varIncludeFile,(Len(varIncludeFile) -
varForwardSlash))
end if
varPOS =
InStrRev(Trim(Request.ServerVariables("PATH_TRANSLATED")),"\",-1,1)
varPath = Left(Trim(Request.ServerVariables("PATH_TRANSLATED")),varPOS)
varFileToRead = varPath & varIncludeFile
Set fso = CreateObject("Scripting.FileSystemObject")
if fso.FileExists(varFileToRead) then
Set f = fso.OpenTextFile(varFileToRead, 1)
ReadAllTextFile = f.ReadAll
Out ReadAllTextFile
else
varFileToRead =
Trim(Request.ServerVariables("APPL_PHYSICAL_PATH")) & "notfound.inc"
Set f = fso.OpenTextFile(varFileToRead, 1)
ReadAllTextFile = f.ReadAll
Out ReadAllTextFile
end if
Set f = Nothing
Set fso = Nothing
END SUB
''''''''''''''''''''''''''''''''''''''''''''''''''
'' Print Out to Browser Sub Routine
'' Required Info Passed to Function: (varOut)
'' varOut = Output to the Browser
''''''''''''''''''''''''''''''''''''''''''''''''''
SUB Out(varOut)
Response.Write varOut
END SUB
--
Anthony Baratta
President
Keyboard Jockeys
"Conformity is the refuge of the unimaginative."
More information about the thelist
mailing list