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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ceate & Display a link w/FileSystemObject

Status
Not open for further replies.

Tivoli0

MIS
Dec 7, 2001
41
IL
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:

Code:
	<%response.write (&quot;<TD ALIGN='left' ><a href ='-- something --'> &quot; & ShowImageForType(objItem.Type) & &quot;&quot;)%></A></TD>
	</TR>
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:
------------------------------
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 <> &quot;dir&quot; Then
		strTemp = LCase(Right(strTemp, Len(strTemp) - InStrRev(strTemp, &quot;.&quot;, -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 &quot;asp&quot;
			strTemp = &quot;asp&quot;
		Case &quot;dir&quot;
			strTemp = &quot;dir&quot;
		Case &quot;htm&quot;, &quot;html&quot;
			strTemp = &quot;htm&quot;
		Case &quot;gif&quot;, &quot;jpg&quot;
			strTemp = &quot;img&quot;
		Case Else
			strTemp = &quot;misc&quot;
	End Select

' The image files are all GIFs and all start with &quot;dir_&quot; .
' They end with one of the values set in the select statement above.

	strTemp = &quot;<IMG SRC=&quot;&quot;./img/dir_&quot; & strTemp & &quot;.gif&quot;&quot; WIDTH=16 HEIGHT=16 	BORDER=0>&quot;

' 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 = &quot;./temp/&quot;

Set objFSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set objFolder = objFSO.GetFolder(Server.MapPath(strPath))
%>

Contents of <B><%= strPath %></B><BR>

<BR>
<TABLE BORDER=&quot;5&quot; BORDERCOLOR=&quot;blue&quot; CELLSPACING=&quot;0&quot; CELLPADDING=&quot;2&quot;>
	<TR BGCOLOR=&quot;#006600&quot;>
		<TD><FONT COLOR=&quot;#FFFFFF&quot;><B>File Name:</B></FONT></TD>
		<TD><FONT COLOR=&quot;#FFFFFF&quot;><B>File Size (bytes):</B></FONT></TD>
		<TD><FONT COLOR=&quot;#FFFFFF&quot;><B>Date Created:</B></FONT></TD>
		<TD><FONT COLOR=&quot;#FFFFFF&quot;><B>File Type:</B></FONT></TD>
	<TR BGCOLOR=&quot;#CCFFCC&quot;>

<%
For Each objItem In objFolder.SubFolders

		<TD ALIGN=&quot;right&quot;><%= objItem.Name %></TD>
		<TD ALIGN=&quot;right&quot;><%= objItem.Size %></TD>
		<TD ALIGN=&quot;left&quot; ><%= objItem.DateCreated %></TD>
		<TD ALIGN=&quot;left&quot; ><%= objItem.Type %></TD>
	</TR>

Next 'objItem

For Each objItem In objFolder.Files
%>
	<TR BGCOLOR=&quot;#CCFFCC&quot;>
		<TD ALIGN=&quot;right&quot;><%= objItem.Name %></TD>
		<TD ALIGN=&quot;right&quot;><%= objItem.Size %></TD>
		<TD ALIGN=&quot;left&quot; ><%= objItem.DateCreated %></TD>
---- the line I'm having problem with --------
Code:
	<%response.write (&quot;<TD ALIGN='left' ><a href ='-- something --'> &quot; & ShowImageForType(objItem.Type) & &quot;&quot;)%></A></TD>
	</TR>
-----------------------------------------

<%
Next 'objItem
 
Set objItem = Nothing
Set objFolder = Nothing
Set objFSO = Nothing

%>
</TABLE>
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
 
Thanks for the reply!

I've checked the link, helped me a little but still don't get what I need.

I've received 404 errs and still couldn't get the icon to be &quot;a herf-able&quot;. Maybe somebody will wake up soon and pitch in. Thanks again -Tivoli0
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top