Hi all,
I am generating a dinamical listing of all files in a directory using the FileSystemObject. The fields I'm producing are filename, date created, size and file type. The file type column shows an icon of the relevent file type, ie if it's an *.asp file then there is an asp.gif icon displayed and if it's an *.htm file there is an htm.gif file etc.
My problem is I want to be able to click on the relevant file type icon and simply have that open up and display the icon file itself. The problematic line is as follow:
I'm having all kind of syntax errors and after a whole day of trying/crying out I'm seeking your help. Here is the full code:
------------------------------
---- the line I'm having problem with --------
I really didn't want to dump all the code, however I thought it will be easier for you guys to understand the logic better as I was having hard time trying to explain the line that caused me the problem.
Thanks for any advice -Tivoli0
I am generating a dinamical listing of all files in a directory using the FileSystemObject. The fields I'm producing are filename, date created, size and file type. The file type column shows an icon of the relevent file type, ie if it's an *.asp file then there is an asp.gif icon displayed and if it's an *.htm file there is an htm.gif file etc.
My problem is I want to be able to click on the relevant file type icon and simply have that open up and display the icon file itself. The problematic line is as follow:
Code:
<%response.write ("<TD ALIGN='left' ><a href ='-- something --'> " & ShowImageForType(objItem.Type) & "")%></A></TD>
</TR>
------------------------------
Code:
<%
' Function that takes a filename and returns the appropriate image for
' that file type based on it's extension.
Function ShowImageForType(strName)
Dim strTemp
' Set string to the one passed in
strTemp = strName
' If it's not a directory, get the extension and set it to strTemp
If strTemp <> "dir" Then
strTemp = LCase(Right(strTemp, Len(strTemp) - InStrRev(strTemp, ".", -1, 1)))
End If
' Set the part of the image file name that's unique to the type of file
' to it's correct value and set this to strTemp.
Select Case strTemp
Case "asp"
strTemp = "asp"
Case "dir"
strTemp = "dir"
Case "htm", "html"
strTemp = "htm"
Case "gif", "jpg"
strTemp = "img"
Case Else
strTemp = "misc"
End Select
' The image files are all GIFs and all start with "dir_" .
' They end with one of the values set in the select statement above.
strTemp = "<IMG SRC=""./img/dir_" & strTemp & ".gif"" WIDTH=16 HEIGHT=16 BORDER=0>"
' Set return value and exit function
ShowImageForType = strTemp
End Function
%>
<%
Dim strPath 'Path of directory to show
Dim objFSO 'FileSystemObject variable
Dim objFolder 'Folder variable
Dim objItem 'Variable used to loop through the contents of the folder
strPath = "./temp/"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(Server.MapPath(strPath))
%>
Contents of <B><%= strPath %></B><BR>
<BR>
<TABLE BORDER="5" BORDERCOLOR="blue" CELLSPACING="0" CELLPADDING="2">
<TR BGCOLOR="#006600">
<TD><FONT COLOR="#FFFFFF"><B>File Name:</B></FONT></TD>
<TD><FONT COLOR="#FFFFFF"><B>File Size (bytes):</B></FONT></TD>
<TD><FONT COLOR="#FFFFFF"><B>Date Created:</B></FONT></TD>
<TD><FONT COLOR="#FFFFFF"><B>File Type:</B></FONT></TD>
<TR BGCOLOR="#CCFFCC">
<%
For Each objItem In objFolder.SubFolders
<TD ALIGN="right"><%= objItem.Name %></TD>
<TD ALIGN="right"><%= objItem.Size %></TD>
<TD ALIGN="left" ><%= objItem.DateCreated %></TD>
<TD ALIGN="left" ><%= objItem.Type %></TD>
</TR>
Next 'objItem
For Each objItem In objFolder.Files
%>
<TR BGCOLOR="#CCFFCC">
<TD ALIGN="right"><%= objItem.Name %></TD>
<TD ALIGN="right"><%= objItem.Size %></TD>
<TD ALIGN="left" ><%= objItem.DateCreated %></TD>
Code:
<%response.write ("<TD ALIGN='left' ><a href ='-- something --'> " & ShowImageForType(objItem.Type) & "")%></A></TD>
</TR>
-----------------------------------------
<%
Next 'objItem
Set objItem = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
%>
</TABLE>
Thanks for any advice -Tivoli0