Forum Moderators: open

Message Too Old, No Replies

Customising IIS Directory listing default page

Which script or page does IIS use to generate the directory indexing page

         

camman

3:49 pm on Mar 31, 2003 (gmt 0)

10+ Year Member



A quick follow on to calimehtar's message.
I'm trying to customise the page that gets generated by IIS for a published folder that has the Directory Browsing option enabled (ie the page that lists the files in the directory).

I'm guessing the page is generated on the fly but I can't find the script that performs this, so that I can edit the HTML it produces. Any ideas?

Thanks in advance

Dreamquick

4:08 pm on Mar 31, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd say the easiest way is just to add your own default asp page which produces the directory listing for you by using something like the file system object to query the directory/file structure etc.

As long as its one of the default page names then it will be used instead of a simple directory listing - giving you absolute control over the appearance of that page...

- Tony

camman

4:32 pm on Mar 31, 2003 (gmt 0)

10+ Year Member



Cheers for your help guys.

One thing though and PLEASE correct me if I'm talking rubbish but........If I wanted to write my own asp I'd surely have to put it in the same directory as and call it the same as, the script that it runs presently or it wont pick it up. In which case I could just edit the current script. However I don't know where it is!

Dreamquick

8:10 pm on Mar 31, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There is no "current script" - IIS will generate a directory listing on your behalf without needing to be asked...

Putting an ASP with one of the default names into that directory will force IIS to run that script instead of generating its default directory listing.

- Tony

camman

8:59 am on Apr 2, 2003 (gmt 0)

10+ Year Member



Aahhh. The penny drops.
Thanks very much for that Dreamquick

camman

3:17 pm on Apr 3, 2003 (gmt 0)

10+ Year Member



If anyone else wants to know how to do it then here's the code:

<%
Dim objFSO, objFile
Dim sMapPath, objFolder

'Create File System Object to get list of files
Set objFSO = CreateObject("Scripting.FileSystemObject")

'Get The path for the web page and its dir, change this setting to view different directories!
sMapPath = server.mapPath("./.") ' this means the current directory

'Set the object folder to the mapped path
Set objFolder = objFSO.GetFolder(sMapPath)
' Then for each file in the object we loop through and print the file and when it was last modified
For Each objFile in objFolder.Files

' Print out a link to the file
Response.Write "<tr><td><a href="""&objFile.Name&""">"
Response.write objFile.Name &" </a></td><td> "& objFile.DateLastModified ' the file name and its date
Response.write " </td></tr>" ' close the tags

Next ' Loop back

' Clear the objects
Set objFSO = Nothing
Set objFolder = Nothing

%>

Just a few tips:

1. Put the ASP in a separate directory to the one you want to list or the ASP will get listed too.

2. Wherever you put the ASP make sure you change the line
sMapPath = server.mapPath("./.") to the directory you want to list eg sMapPath = server.mapPath("./this_directory") AND change the line <a href="""&objFile.Name&"""> to that directory too eg <a href=""this_directory/"&objFile.Name&""">

3. You can call the ASP anything you like and point to it but you could also, as Dreamquick stated, call it one of the default name such as index.asp or default.asp so that the server automatically runs it.

4. You might want to change the HTML code a bit if you don't want it in a table however you'll need to put a <br> at the end to get the format correct.