Discussion Locked

Display file directory on a web page

0 helpful
9 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I am looking for a "grabber" or way to display the contents of a server directory (with links) on one of my web pages without using frames or Java. I am looking for maybe XML or a simple script or include to point a part of my page to an existing directory.
Example: I want to be able to click on a link that goes to a page showing what files are available in a particular directory on my server- like a grabber of information.
I am using IIS 5 on Win2K server.
Any advice/ help would be great. THANK YOU.

9 replies

by andrew

If you know the folder ahead of time, you can just create a virtual directory mapped to it, and enable (allow) directory browsing.

When a user browses to this virtual directory, a list of sub-folders and files is shown, allowing the user drill down, download files, etc.

by andrew

If you need to do in all in ASP, here's a method that will recurse the folder structure:

Private Sub RecurseFolders(sStartPath As String)
Dim oFSO As Scripting.FileSystemObject
Dim oFolders As Scripting.Folders
Dim oFolder As Scripting.FolderDim oSubFolder As Scripting.Folder
Dim oFiles As Scripting.Files
Dim oFile As Scripting.File

Set oFSO = New Scripting.FileSystemObject
Set oFolder = oFSO.GetFolder(sStartPath)
Set oFiles = oFolder.Files
For Each oFile In oFiles
'output the HTML file items list here
'oFile.Path & "\" & oFile.Name
Next

Set oFolders = oFolder.SubFolders
For Each oSubFolder In oFolders
RecurseFolders oSubFolder.Path
Next
End Sub

You'lljust need add the HTML generation code.

by andrew

That's VB code. You'll have to tweak it (get rid of type in the Dims, use Server.CreateObject instead of New, etc.) to get it into VBScript.

by ian_c

Easiest way is to enable directory listing for that folder on IIS. If you don't place a default page in that directory, users will be presented with a list of each file name as a hyperlink. You can configure this through the console.

e.g. you have a directory /content/documents/ containing these files, and your site is configured to see index.htm as the default document. As long as the \content\documents folder doesn't contain a file called index.htm, linking to /content/documents/ will display the list of links you require.

by younghorses

I'm sorry if I was unclear. I am not looking for a way to point an entire page to a directory (using an "a href") I want to be able to display the contents of the directory on a small corner of the entire page without using frames to do so. Thanks.

by jay eckles

Try this ASP - for the most part it is taken directly out of Teach Yourself ASP in 21 Days by Mitchell and Atkinson. You'll have to change "directory" to the dir you want to list the contents of. Also, this will only list files, not subdirectories, but I think that's what you want. I haven't tested it, but if you have any problems, they should be pretty easy to work out.

If you want a complete, tested solution, email me about contracting me for the job.

<%
Dim fso, file, folder
set fso = Server.CreateObject( "Scripting.FileSystemObject" )
set folder = fso.GetFolder( Server.MapPath( "directory" ) )

for each file in folder.Files
Response.write ""&file.Name&"
next
set folder = Nothing
set fso = Nothing
%>

Jay Eckles
www.jayeckles.com

This discussion is closed to new replies.