This demo was given as part of the monthly question winners. This person wanted to make a Table of Contents from all documents listed in a Directory. Thanks to Alex Homer for this. Nice thing is make this your Default page and you never have to maintain your Table Of Contents for that particular directory! Copy and paste this code into a blank document, name it Default.htm and Poof! Your instant Table Of Contents is done!
Here's the code
<%@ LANGUAGE=VBSCRIPT %>
<%
Server.ScriptTimeOut = 300 'the page may take a while to run
strMenuPageURL = "/menu.htm" 'full virtual path to new menu page
strListFolder = "/" 'directory holding files to be listed
'NB: List folder must end with a backslash, for example "/test/"
'You also need to make sure that the IURS_machinename accoutn has
'permission to write and delete files in the target directory
%>
<HTML>
<BODY>
<%
Response.Write "<P>Creating menu page: " & strMenuPageURL & " ...</P>"
'create a new text file that will be the HTML menu page
Set objFSO = CreateObject("Scripting.FileSystemObject")
strFileName = Server.MapPath(strMenuPageURL)
Set objMenuPage = objFSO.CreateTextFile(strFileName, True) 'overwrite
'write the page heading to the new menu page file
objMenuPage.WriteLine "<HTML><BODY><P><B>List of files available</B></P>"
'create a collection of the files in the specified folder
Set objFolder = objFSO.GetFolder(Server.MapPath(strListFolder))
Set colFiles = objFolder.Files
'read each file and extract the title to build a menu page
For Each objFile in colFiles
'get the file extension and see if it's an ASP or HTML page
strFileType = objFSO.GetExtensionName(objFile.Name)
If (strFileType = "asp") Or (Left(strFileType, 3) = "htm") Then
'read the file contents into a string
Set objStream = objFile.OpenAsTextStream(1) 'for reading
strContent = objStream.ReadAll
objStream.Close
'extract the title from the page if there is one
strTitle = ""
intStart = Instr(UCase(strContent), "<TITLE>") + 7
intFinish = Instr(UCase(strContent), "</TITLE>")
If (intStart > 0) And (intFinish > intStart) Then
strTitle = Trim(Mid(strContent, intStart, intFinish - intStart))
End If
If Len(strTitle) = 0 Then strTitle = "Untitled page '" & objFile.Name & "'"
'create the text for a link in the menu page
strThisFileURL = strListFolder & objFile.Name
strLink = "<A HREF=" & Chr(34) & strThisFileURL _
& Chr(34) & ">" & strTitle & "</A><BR>"
objMenuPage.WriteLine(strLink)
End If
Next
'write the closing HTML elements
objMenuPage.WriteLine "</BODY></HTML>"
objMenuPage.Close
Response.Write "<P>Done.</P>"
%>
<P><A HREF="<% = strMenuPageURL %>">Open the Menu Page</A></P>
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More ASP Code Articles
More By aspfree
developerWorks - FREE Tools! |
<a href="http://zeus.developershed.com/shonuff.php?blackbird=3853&zoneid=442&source=&dest=http%3A%2F%2Fwww.ibm.com%2Fdeveloperworks%2Fspaces%2Fjazz%3FS_TACT%3D105AGY31%26S_CMP%3DDEVSHED&ismap="><img src="http://images.devshed.com/corp/img/news/jazz01.gif" alt="developerWorks Jazz space" align="left"></a>You've heard the buzz about Jazz... want to know more about it from a developer's perspective? Check out the Jazz space on developerWorks. This space is an up-to-date resource for developers, including technical information about Jazz and products built on Jazz, like Rational Team Concert Express. The Jazz space includes content from a wide variety of sources, including links, feeds, and comments from experts. FREE! Go There Now!
|
|
|
|
As businesses grow increasingly dependent upon Web applications to provide services to customers, employees and partners, these complex applications become more difficult to secure. Although traditional security solutions protect Internet infrastructure layers, they do not guard against HTTP and HTML attacks. Many organizations that conduct security testing still deploy applications that allow attackers to manipulate their logic and wreak havoc on their business. To mitigate this risk, development and delivery teams must address Web application security throughout the lifecycle, addressing the many layers detailed in this paper. FREE! Go There Now!
|
|
|
|
Join us for this on demand webcast to learn about developing complex systems more quickly and efficiently. We'll cover market drivers for developing, governing and reusing systems software assets and how you can develop system software assets with Rational Asset Manager. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download the latest trial version of IBM Data Studio V1.1 at no cost. IBM Data Studio is a comprehensive data management solution that helps you effectively design, develop, deploy and manage your data, databases, and database applications throughout the data management life cycle utilizing a consistent and integrated user interface. Unlike other client-side data management solutions that focus on only one aspect of the application lifecycle or database administration, Data Studio complements the Rational Software Delivery platform, providing unparalleled flexibility for a heterogeneous data server environment across platforms. FREE! Go There Now!
|
|
|
|
This tutorial shows new users of IBM WebSphere Business Monitor Version 6.0.2 how to perform the "Hello World" equivalent for monitoring business process applications. It is intended to help you get familiar with the capabilities of the product. FREE! Go There Now!
|
|
|
|
Learn from the best! Find out how developers use Rational ClearCase to be more flexible, innovative and deliver higher quality code in the Rational ClearCase Power Users eKit. This complimentary eKit provides a collection of materials, like articles, whitepapers, and demos that can help you become a power user of Rational ClearCase. FREE! Go There Now!
|
|
|
|
Learn the basics of the IBM Customer Information Control System (CICS). With a hands-on exercise, learn how to get your first CICS application up and running on your desktop using TXSeries V6.1 for Windows. The tutorial shows you how to download and install a free trial version of TXSeries V6.1. FREE! Go There Now!
|
|
|
|
Regression testing -- in which code is thoroughly tested to ensure that changes have not produced unexpected results -- is an important part of any development process. But many testing environments neglect the terminal-based applications that still form the backbone of many industries. In this tutorial, you'll learn how the Rational Functional Tester Extension for Terminal-Based Applications works with other Rational Functional Tester to help test terminal-based applications quickly and easily. FREE! Go There Now!
|
|
|
|
Informix Dynamic Server (IDS) Express Edition offers outstanding online transaction processing (OLTP) database performance, while helping to simplify and automate many of the tasks associated with deploying databases for small business applications. IDS 11 further extends the ease of management and applications integration with the Admin API and Scheduler, high availability with Continuous Log Restore for backup server recovery in case of a primary server failure, and column level encryption to protect personal and company private data. FREE! Go There Now!
|
|
|
|
The discipline of assembling and delivering software is maturing beyond standard developer-centric compile/test software builds. The end-to-end software development lifecycle is emerging as the new focus moves “Beyond the Build.” Join this on demand webcast to learn about methods for streamlining software delivery and key capabilities of the IBM Rational Build Forge framework for automating build and release management in environments of any size. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |