Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple ASP code needed to display & not display 1

Status
Not open for further replies.

JGKWORK

IS-IT--Management
Apr 1, 2003
342
GB
Hi,
I have the following code to list contents of a folder. I need to know the code to do the following:

1/. change the code so that it doesn't show the file "default.asp" or the folder "Images".

2/. Seperate from above I need to know how I WOULD SHOW ONLY the file "index.htm"

could some one help, thanks very much:



<%@LANGUAGE=&quot;VBSCRIPT&quot;%>
<%
Option Explicit
On Error Resume Next

' this section is optional - it just denies anonymous access
If Request.ServerVariables(&quot;LOGON_USER&quot;)=&quot;&quot; Then
Response.Status = &quot;401 Access Denied&quot;
End If

' declare variables
Dim objFSO, objFolder
Dim objCollection, objItem

Dim strPhysicalPath, strTitle, strServerName
Dim strPath, strTemp
Dim strName, strFile, strExt, strAttr
Dim intSizeB, intSizeK, intAttr, dtmDate

' declare constants
Const vbReadOnly = 1
Const vbHidden = 2
Const vbSystem = 4
Const vbVolume = 8
Const vbDirectory = 16
Const vbArchive = 32
Const vbAlias = 64
Const vbCompressed = 128

' don't cache the page
Response.AddHeader &quot;Pragma&quot;, &quot;No-Cache&quot;
Response.CacheControl = &quot;Private&quot;

' get the current folder URL path
strTemp = Mid(Request.ServerVariables(&quot;URL&quot;),2)
strPath = &quot;&quot;

Do While Instr(strTemp,&quot;/&quot;)
strPath = strPath & Left(strTemp,Instr(strTemp,&quot;/&quot;))
strTemp = Mid(strTemp,Instr(strTemp,&quot;/&quot;)+1)
Loop

strPath = &quot;/&quot; & strPath

' build the page title
strServerName = UCase(Request.ServerVariables(&quot;SERVER_NAME&quot;))
strTitle = &quot;Contents of the &quot; & strPath & &quot; folder&quot;

' create the file system objects
strPhysicalPath = Server.MapPath(strPath)
Set objFSO = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set objFolder = objFSO.GetFolder(strPhysicalPath)
%>
<html>
<head>
<title><%=strServerName%> - <%=strTitle%></title>
<meta name=&quot;GENERATOR&quot; content=&quot;The Mighty Hand of Bob&quot;>
</head>
<body bgcolor=&quot;#FFFFFF&quot;>
<table width=&quot;906&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; height=&quot;26&quot;>
<tr>
<td width=&quot;283&quot;><img src=&quot;/images/coatbridge.gif&quot; width=&quot;208&quot; height=&quot;69&quot;></td>
<td width=&quot;378&quot;>
<div align=&quot;center&quot;><img src=&quot;/NLN_Materials/Images/NLNMDIT.gif&quot; width=&quot;120&quot; height=&quot;100&quot;></div>
</td>
<td width=&quot;245&quot;> </td>
</tr>
</table>
<h1 align=&quot;left&quot;> </h1>
<div align=&quot;center&quot;><center>
<table width=&quot;40%&quot; border=&quot;1&quot; cellspacing=&quot;1&quot; cellpadding=&quot;2&quot; bordercolor=&quot;#CCCCCC&quot;>
<tr>
<th align=&quot;left&quot; bgcolor=&quot;#003366&quot;><font color=&quot;#FFFFFF&quot;>Course Material:</font></th>
</tr>
<%
''''''''''''''''''''''''''''''''''''''''
' output the folder list
''''''''''''''''''''''''''''''''''''''''

Set objCollection = objFolder.SubFolders

For Each objItem in objCollection
strName = objItem.Name
strAttr = MakeAttr(objItem.Attributes)
dtmDate = CDate(objItem.DateLastModified)
%>
<tr>
<td align=&quot;left&quot;><b><a href=&quot;<%=strName%>&quot;><%=strName%></a></b></td>
</tr>
<% Next %>
<%
''''''''''''''''''''''''''''''''''''''''
' output the file list
''''''''''''''''''''''''''''''''''''''''

Set objCollection = objFolder.Files

For Each objItem in objCollection
strName = objItem.Name
strFile = Server.HTMLEncode(Lcase(strName))

intSizeB = objItem.Size
intSizeK = Int((intSizeB/1024) + .5)
If intSizeK = 0 Then intSizeK = 1

strAttr = MakeAttr(objItem.Attributes)
strName = Ucase(objItem.ShortName)
If Instr(strName,&quot;.&quot;) Then strExt = Right(strName,Len(strName)-Instr(strName,&quot;.&quot;)) Else strExt = &quot;&quot;
dtmDate = CDate(objItem.DateLastModified)
%>
<tr>
<td align=&quot;left&quot;><a href=&quot;<%=strFile%>&quot;><%=strFile%></a></td>
</tr>
<% Next %>
</table>
</center></div>

</body>
</html>
<%
Set objFSO = Nothing
Set objFolder = Nothing

' this adds the IIf() function to VBScript
Function IIf(i,j,k)
If i Then IIf = j Else IIf = k
End Function

' this function creates a string from the file atttributes
Function MakeAttr(intAttr)
MakeAttr = MakeAttr & IIf(intAttr And vbArchive,&quot;A&quot;,&quot;-&quot;)
MakeAttr = MakeAttr & IIf(intAttr And vbSystem,&quot;S&quot;,&quot;-&quot;)
MakeAttr = MakeAttr & IIf(intAttr And vbHidden,&quot;H&quot;,&quot;-&quot;)
MakeAttr = MakeAttr & IIf(intAttr And vbReadOnly,&quot;R&quot;,&quot;-&quot;)
End Function
%>
 
It works on my server as you can see, I'm trying to eliminate things from the equation.


BTW I'm UK also

Chris.

Indifference will be the downfall of mankind, but who cares?
 
I see there is a new nit of code below the 'output folder list'

URLName = strName & &quot;/index.htm&quot;
if lcase(strName) <> &quot;_notes&quot; then

(I didn't have that in my previous code) could that be the answer?
 
Morning,

That is just so the Dreamweaver notes folder won't appear on the list, Other than that it is your code. Taken out the images and user logon bit because when you've tried it twice and logged on twice it gets a bit wearing.

The only thing I think of the app is locked into the server cache for some reason, on my test server I limit the server script file cache, You wouldn't really want to do this on a production server ( properties, Home Directory, Configuration... Process Options). Before you do this it may be worth stopping and starting the site just to try and release anything that may be locked in.
The biggest problem is that when something like this hits you you start looking far too deep into the problem and miss the blindingly obvious ( or maybe that's just me ).
It may be worth setting up a new site on the server and using DNS and host headers to point to it, then copying your file structure across along with the newest version of default.asp and seeing if that works ok.
Something else worth checking is the server logs to see if you are getting a HTTP response code of 200 each time the default page is accessed.


Chris.
Indifference will be the downfall of mankind, but who cares?
 
Woops, gave the star but didn't post the post!

Yes it is a GOOD morning! Guess what? that last bit of code you sent works! woohoo!

I think maybe I must have left out the URLName = strName & &quot;/index.htm&quot; in the output folder list (i only included it in the output of the file list).

Many many thanks, (& thanks for sticking with it)

Cheers, JGK.
 
Excellent

Glad it finally works

Cheers for the star.

Chris. Indifference will be the downfall of mankind, but who cares?
 
If you want to the server to display the index.htm file autmatically, you can also add it in IIS. In IIS, right-click on the Default Web Site (or appropriate) and select Properties. Then enter the Documents tab, and add filenames you want the server to support, such as:
default.asp
default.aspx
default.htm
index.htm
index.html

Palooka
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top