chris leeds said:
Thanks Jim,
this is pretty much what I was looking for.
If you, or anyone else, knows of a resource (tutorial or example) that goes
into the detail about what and how each of these lines works I'd appreciate
it.
I can "sort of" understand what you've written but I lack enough underlying
skill to put it into action with any kind of confidence.
Oh, all right, just because someone else recently asked the same
question.
Here's a complete page that does the job. If you save this page as
includebody.asp and then browse
includebody.asp?inc=content.htm
it will display the body section of content/content.htm whereever the
<%IncludeBody(request("inc"))%>
tag appears.
To modify the path from the page that contains the IncludeBody
subroutine to the page whose body section you want to include, modify
this statement.
const IncludePath = "content/"
<%option explicit%>
<html>
<head>
<title>Include Body Example</title>
</head>
<body>
<%
Sub IncludeBody(aUrl)
const ForReading = 1
const FormatAscii = 0
const IncludePath = "content/"
Dim regEx
Dim bodyUrl
Dim fso
Dim physFile
Dim tsPage
Dim strPage
Dim intBodBeg
Dim intBodEnd
bodyUrl = trim(aUrl)
If bodyUrl = "" Then
response.write "No file specified."
Exit Sub
End If
' Verify syntax of include URL is alphanumeric.alphanumeric
' (To avoid file system exploits.)
Set regEx = New RegExp
regEx.Pattern = "^[a-zA-Z0-9]+\x2e[a-zA-Z0-9]+$"
If Not regEx.Test(bodyUrl) Then
response.write "Illegal file name."
Exit Sub
End If
' Translate include URL to physical path and verify it exists.
set fso = server.createobject("scripting.filesystemobject")
physFile = server.mappath(IncludePath & bodyUrl)
If Not fso.FileExists(physfile) Then
response.write "File not found."
Exit Sub
End If
' Copy physical file into strPage variable.
set tsPage = fso.OpenTextFile(physFile, ForReading, False,
FormatAscii)
strPage = tsPage.ReadAll
tsPage.close
' Chop off everything up to and including the <body> tag.
intBodBeg = InStr(lcase(strPage), "<body")
If intBodBeg > 0 Then
intBodEnd = instr(intBodBeg, strPage, ">")
If intBodEnd > 0 Then
strPage = mid(strPage, intBodEnd + 1)
End If
End If
' Chop off the </body> tag and anything that follows.
intBodEnd = instr(lcase(strPage), "</body")
If intBodEnd > 0 Then
strPage = left(strPage, intBodEnd - 1)
End If
' Send whatever remains to the visitor.
response.write strPage
End Sub
%>
<h1 align=center>Include Body Example</h1>
<%IncludeBody(request("inc"))%>
<hr>
<p>Page Footer</p>
</body>
</html>
Jim Buyens
Microsoft FrontPage MVP
http://www.interlacken.com
Author of:
*----------------------------------------------------
|\---------------------------------------------------
|| Microsoft Office FrontPage 2003 Inside Out
||---------------------------------------------------
|| Web Database Development Step by Step .NET Edition
|| Microsoft FrontPage Version 2002 Inside Out
|| Faster Smarter Beginning Programming
|| (All from Microsoft Press)
|/---------------------------------------------------
*----------------------------------------------------