Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Article ID: 218606 - Last Review: July 7, 2008 - Revision: 6.2
How To Use ASP and Scripting.FileSystemObject to Create a Dynamic Table of Contents Page
This article was previously published under Q218606
We strongly recommend that all users upgrade to Microsoft Internet Information Services (IIS) version 7.0 running on Microsoft Windows Server 2008. IIS 7.0 significantly increases Web infrastructure security. For more information about IIS security-related topics, visit the following Microsoft Web site:
For more information about IIS 7.0, visit the following Microsoft Web site:
This step-by-step article shows an example of how to use an
Active Server Page (ASP) to create a dynamic table of contents for a Web site
that is updated frequently. Active Server Pages makes it easier to keep Web
sites up to date without having to manually update a contents page.
Create a Table of Contents
Microsoft
provides programming examples for illustration only, without warranty either
expressed or implied. This includes, but is not limited to, the implied
warranties of merchantability or fitness for a particular purpose. This article
assumes that you are familiar with the programming language that is being
demonstrated and with the tools that are used to create and to debug
procedures. Microsoft support engineers can help explain the functionality of a
particular procedure, but they will not modify these examples to provide added
functionality or construct procedures to meet your specific requirements.
The following ASP code is designed to create a table of
contents from the files that are listed in the "docs" subfolder. To use this
example, copy the ASP code in to a file, and then save the file as
contents.asp in a folder that has at least "Script"
access. To change the location of the folder to display, change the line of
code that defines the
strDocsPath variable.
<%@LANGUAGE="VBSCRIPT"%>
<%
Option Explicit
Dim strDocsPath, strDocsPhysicalPath
Dim objFSO, objFolder, objFiles, objFile
Dim strName, strFile, strType, lngSize
' NOTE: set the following line to the folder to display
strDocsPath = "docs"
' map the folder to a physical path
strDocsPhysicalPath = Server.MapPath(strDocsPath)
' create a system file object
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
' create an object for the folder
Set objFolder = objFSO.GetFolder(strDocsPhysicalPath)
%>
<html>
<head>
<title>Table Of Contents</title>
</head>
<body>
<h1 align="center">Table Of Contents</h1>
<h4>Please choose the Document to view.</h4>
<ul>
<%
' create a files collection
Set objFiles = objFolder.Files
' step through the files collection
For Each objFile in objFiles
' get a file's name
strName = objFile.Name
' make it lowercase for the URL
strFile = Lcase(strName)
' get the file's type
strType = objFile.Type
' make the name a title for display
strName = MakeTitle(strName)
' get the file size in KB
lngSize = objFile.Size\1024
' output the filename and URL
Response.Write "<li><a href=""" & strDocsPath & "" & strFile & """>" & strName & "</a><br>"
' output the file's size and type
Response.Write "<em>(" & lngSize & "KB " & strType & ")</em></li>" & vbCrLf
Next
' this function drops the extension from a file
Function MakeTitle(strTemp)
If InStrRev(strTemp,".") Then
strTemp = Left(strTemp,InStrRev(strTemp,".")-1)
End If
MakeTitle = strTemp
End Function
%>
</ul>
</body>
</html>
For more information about Microsoft Scripting
Technologies, visit the following Microsoft Web site:
APPLIES TO
- Microsoft Internet Information Server 4.0
- Microsoft Internet Information Services 5.0
- Microsoft Internet Information Services 6.0
- Microsoft Internet Information Services 7.0
| kbfso kbhowtomaster KB218606 |
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate