Click to See Complete Forum and Search --> : How to display a list of .CSV files in a webpage?
squale
03-29-2005, 11:41 AM
I have a vbscript that runs on my computer that takes a number of .csv files, and puts them into a directory. Well I want to be able to make a webpage that will be able to read ALL of the .csv files in that directory and make like a drop-down listing of them. Then the user can choose a specific .csv file from the drop down and view it's results either directly inside the page or by having MS Excel open up. How would I create a page that can do this?
Thanks a lot!
lmf232s
03-29-2005, 01:39 PM
You can use FSO to read the directory and for each file, display it in a drop down box. I dont know the FSO code but it will go like this
<Select name=txtFiles>
<option value="">Please Select a File
<%For each sFile in FSO%>
<option value="<%=FileName">><%=FileName%>
<%Next%>
</select>
The only part missing is the code to read the directory. Im sure someone on here can help you with the File System object or just do a goole on it and youll get tons of results.
phpnovice
03-29-2005, 04:39 PM
Actually, this would be closer:
<Select name=txtFiles>
<option value="">Please Select a File</option>
<%For each sFile in FSO%>
<option value="<%=sFile.Name">><%=sFile.Name%></option>
<%Next%>
</select>
This evening I can post the full FSO code and table formatting for a complete directory list of your selected files -- including displaying all file attributes.
If you want it. ;)
squale
03-29-2005, 05:00 PM
that would be great, thanks
phpnovice
03-29-2005, 07:00 PM
<%
Function GetFileAttributes(nFileAttributes)
Dim strAttributes
strAttributes = ""
If nFileAttributes And 0 Then
strAttributes = strAttributes & "n"
Else
strAttributes = strAttributes & " "
End If
If nFileAttributes And 1 Then
strAttributes = strAttributes & "r"
Else
strAttributes = strAttributes & " "
End If
If nFileAttributes And 2 Then
strAttributes = strAttributes & "h"
Else
strAttributes = strAttributes & " "
End If
If nFileAttributes And 4 Then
strAttributes = strAttributes & "s"
Else
strAttributes = strAttributes & " "
End If
If nFileAttributes And 8 Then
strAttributes = strAttributes & "v"
Else
strAttributes = strAttributes & " "
End If
If nFileAttributes And 16 Then
strAttributes = strAttributes & "d"
Else
strAttributes = strAttributes & " "
End If
If nFileAttributes And 32 Then
strAttributes = strAttributes & "a"
Else
strAttributes = strAttributes & " "
End If
If nFileAttributes And 64 Then
strAttributes = strAttributes & "l"
Else
strAttributes = strAttributes & " "
End If
If nFileAttributes And 128 Then
strAttributes = strAttributes & "c"
Else
strAttributes = strAttributes & " "
End If
GetFileAttributes = strAttributes
End Function
%>
<style type="text/css">
<!--
.cell { padding-left: 5px; padding-right: 5px; }
.fixed { font-family: Courier New; padding-left: 5px; padding-right: 5px; }
-->
</style>
<table border="1" cellspacing="0" cellpadding="0">
<tr>
<th><u>File Name</u></th>
<th><u>Size</u></th>
<th><u>Type</u></th>
<th><u>Created</u></th>
<th><u>Updated</u></th>
<th><u>Attr.</u></th>
</tr>
<%
Dim objFSO, objFolder, objFile, strPath
strPath = Server.MapPath("/downloads/")
'
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strPath)
'
For Each objFile in objFolder.Files
' add code here to select files to display -- default = all
%>
<tr>
<td align="left" class="cell"><% = objFile.Name %>&nbsp;</td>
<td align="right" class="cell"><% = objFile.Size %>&nbsp;</td>
<td align="left" class="cell"><% = objFile.Type %>&nbsp;</td>
<td align="right" class="cell"><% = objFile.DateCreated %>&nbsp;</td>
<td align="right" class="cell"><% = objFile.DateLastModified %>&nbsp;</td>
<td align="left" class="fixed"><% = GetFileAttributes(objFile.Attributes) %>&nbsp;</td>
</tr>
<%
Next
'
Set objFile = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
%>
</table>