I have a vbscript that retrieves pdf files and outputs them in a table
with a link to the file plus the date modified. I'm trying with no
luck to sort the links starting with newest file. The file path is
newbusiness/2007. There is a folder for each year. A the top of the
table is a list of links to each year folder. Below is the code:
<%@ Language = "vbScript"%>
<%option Explicit%>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<%
'
****************************************************************************************************
' FSO - Datasource - path to the icon Folder
'
****************************************************************************************************
Dim ObjFSO
Set ObjFSO = CreateObject("Scripting.FileSystemObject") '** Create
FSO
Function getCurrentYear()
getCurrentYear = DatePart("yyyy", Date)
if not ObjFSO.FolderExists(Server.MapPath("newbusiness\" &
getCurrentYear)) then
getCurrentYear = getCurrentYear - 1
end if
Exit Function
End Function
Dim FolderRequest : FolderRequest = Request.QueryString("archive") &
"\" '** grabs the query string passed by the argument "?folder="
If FolderRequest = "\" or Len(Request.QueryString) = 0 then
If ObjFSO.FolderExists(Server.MapPath("newbusiness\" &
getCurrentYear)) then
FolderRequest = getCurrentYear & "\"
else
getCurrentYear = getCurrentYear - 1
FolderRequest = getCurrentYear & "\"
end if
end if
Dim FolderPath
FolderPath="newbusiness\" & FolderRequest '** newbusiness folder
path/
Dim RootFolder, NavPath, s, n
Dim f1
Dim sf
MapMyDrive()
'==============================================================
' Sets up the folder path where the pdf files will be read from
'==============================================================
Private Sub MapMyDrive()
On Error Resume Next
Set RootFolder = ObjFSO.GetFolder(Server.MapPath(FolderPath))
If Err.Number <> 0 then
FolderPath = "newbusiness\" & getCurrentYear & "\" '** newbusiness
folder path/
Err.Clear()
else
FolderPath= "newbusiness\" & FolderRequest
end if
Set RootFolder = ObjFSO.GetFolder(Server.MapPath("newbusiness/"))
'** Root folder = New Business folder
Set NavPath = ObjFSO.GetFolder(Server.MapPath(FolderPath)) '**
set what files are shownview depending on what's defined in NavPath
Set sf = RootFolder.SubFolders '** set subfolders to read information
from the /newbusiness folder (top level directory)
Exit Sub
End Sub
Function ShowFolderList(folderspec) '** grabs all the files within a
specific folder and outputs them, with links, as a single string
Dim n
n = 0
For Each f1 in sf
n = n + 1
if n = 1 then
'=== Do Nothing ===
else
s = s & "<font color='#ffffff'>|</font> "
end if
s = s & "<nobr><a href='newbusiness.asp?archive=" & f1.name & "'>" &
UCase(replace(f1.name ,"_"," ")) & "</a></nobr> "
Next
ShowFolderList = s
End Function
'
****************************************************************************************************
' Outer table
'
****************************************************************************************************
%>
<!doctype html public "-//w3c//dtd html 4.0 transitional//en" >
<html>
<head>
<TITLE>New Business Archive for
<%response.Write(replace(replace(FolderRequest, "\", "") ,"_"," "))
%>
</TITLE>
<link rel="stylesheet" href="/CityOfRichmondVirginia.css">
<link rel="stylesheet" href="newbusinessarchive.css" title="New
Business Archive Style Sheet">
</head>
<body bgcolor="#E2DED4" text="#000000" link="#000000" vlink="#000000"
alink="#000000" leftmargin="0" topmargin="0" rightmargin="0"
bottommargin="0" marginwidth="0" marginheight="0" name="top">
<form name="frmMain" method="post" action="index.aspx" id="frmMain">
<input type="hidden" name="__VIEWSTATE" value="dDwxMzE4OTY3MjM2Ozs
+cEc8jXCd4QzwkdirzxyX1EgPR0c=" ID="Hidden1"/>
<div align="center">
<table bgcolor="#333333" width="760" cellspacing="0"
cellpadding="1" border="0" style="background:#333333;width:760px;"
ID="Table1">
<!-- Begin table creating 1px border -->
<tr>
<td>
<table background="" bgcolor="#E2DED4" width="100%"
cellspacing="0" cellpadding="0" border="0" ID="Table3">
<tr>
<td align="center"><script src="/macromediaflashdetect.js"
type="text/javascript"></script>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/
swflash.cab#version=6,0,0,0" width="758" height="98"
id="Richmond.Main.Menu" align="middle" >
<param name="movie" value="/PageTemplates/flash/
Richmond.Main.Menu.Smaller.swf?
__ServerName=wwwdev&__PageTemplateName=Default&__PageTemplateType=SmallDeptHeader" /
>
<param name="menu" value="false" />
<param name="allowScriptAccess" value="sameDomain" />
<param name="quality" value="high" />
<param name="scale" value="noscale" />
<param name="wmode" value="transparent" />
<param name="loop" value="false" />
<param name="bgcolor" value="#E2DED4" />
<embed src="/PageTemplates/flash/
Richmond.Main.Menu.Smaller.swf?
__ServerName=wwwdev&__PageTemplateName=Default&__PageTemplateType=SmallDeptHeader"
loop="false" menu="false" quality="high" scale="noscale"
wmode="transparent" bgcolor="#E2DED4" width="758" height="98"
name="Richmond.Main.Menu" align="middle"
allowScriptAccess="sameDomain" type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
</td>
</tr>
<tr height="15" bgcolor="FEF8E8">
<td></td>
</tr>
<tr>
<td align="center" bgcolor="FEF8E8">
<!-- BEGIN "YOUR DEPARTMENT" CONTENT -->
<table bgcolor="#333333" width="760" border="0" cellpadding="1"
cellspacing="0" align="center"
ID="Table4">
<tr>
<td valign="top" bgcolor="#99cccc">
<table width="100%" border="0" cellspacing="0" cellpadding="1"
ID="Table5">
<tr bgcolor="">
<td colspan="2" align="center">
<span class="pagetitleteal">New Business Archive</
span><br><br>
</td>
</tr>
<tr bgcolor="#999999">
<td colspan="2" align="center">
<%Response.Write "<B>"&ShowFolderList(sf)&"</B>" %>
</td>
</tr>
<tr>
<td colspan="2">
<table width="100%" cellpadding="3" cellspacing="0"
border="1">
<%
'
***************************************************************************************************
' Display pdf files and tables in specific folder
'
***************************************************************************************************
Dim files, fileCountIndex
Set files = NavPath.Files
fileCountIndex = files.count
'
****************************************************************************************************
' Display Number of picture
'
****************************************************************************************************
'Determine how many files are in the directory, and create the
table entries accordingly.
if fileCountIndex = 0 then
Response.Write "<tr><td colspan='2' valign='bottom'>There are <b>"
& fileCountIndex & "</b> records available.<BR>Please choose a
directory above to browse.<br>" _
& "The current list of new business licenses is: " &
setCurrentLicense() & "</td></tr>"
else
if fileCountIndex = 1 then
Response.Write "<tr><td colspan='2' valign='bottom'>There is
<b>" & fileCountIndex & "</b> record available.<br>"_
& "The current list of new business licenses is: " &
setCurrentLicense() & "</td></tr><tr><td align='center'><b>Week
Ending</b></td><td align='center'><b>Posted Date</b></td></tr>"
else
if fileCountIndex >= 2 then
Response.Write "<tr><td colspan='2' valign='bottom'>There are
<b>" & fileCountIndex & "</b> records available.<br>" _
& "The current list of new business licenses is: " &
setCurrentLicense() & "</td></tr><tr><td align='center'><b>Week
Ending</b></td><td align='center'><b>Posted Date</b></td></tr>"
end if
end if
end if
'Code goes here to set the menu navigation
'
=============================================================================
'
===
===
' === Daniel
Dority ===
'
=============================================================================
getHerDone()
'
=============================================================================
' === Outputs the directory of PDFs onto the
page ===
'
=============================================================================
Private Sub getHerDone()
Dim i : i = 0
Dim Name, file, myExt, Link
For Each file in Files
Name = File.Name
Link = Name
myExt = LCase(ObjFSO.GetExtensionName(Name))
Select Case(myExt)
Case "pdf":
Response.Write("<tr>")
Response.Write(" <td valign='middle' width='420'>")
Response.Write(addLinkage(FolderPath, Link,
formatString(Name)))
Response.Write(" </td>")
Response.Write(" <td width='220'>" & (File.DateLastModified) &
"</td>")
Response.Write("</tr>")
Case Else: '=== Do Nothing ===
End Select
Next
Exit Sub
End Sub
'
=============================================================================
' === Gets the latest file in the latest
folder ===
'
=============================================================================
Private Function setCurrentLicense()
Dim currentFolderPath, file, currentFiles, currentFileCountIndex,
currentNavPath
currentFolderPath = "newbusiness\" & getCurrentYear & "\"
Set currentNavPath =
ObjFSO.GetFolder(Server.MapPath(currentFolderPath)) '** set what files
are shownview depending on what's defined in NavPath
Set currentFiles = currentNavPath.Files
currentFileCountIndex = currentFiles.count
Dim i : i = 1
For Each file in currentfiles
Select Case (i = currentFileCountIndex)
Case True: setCurrentLicense = addLinkage(currentFolderPath,
file.Name, formatString(file.Name))
Case Else: '=== Do Nothing ===
End Select
i = i + 1
Next
Set currentNavpath = Nothing
Set currentFiles = Nothing
Exit Function
End Function
'
=============================================================================
' === Formats the filename from "newbusinessMMDDYYYY" to "MM/DD/
YYYY." ===
' ===
ARGUMENTS:
===
' === strLicense -
file.Name ===
'
=============================================================================
Private Function formatString(strLicense)
formatString = Left(Right(replace(strLicense ,"_"," "), 12), 2) _
& "/" & Left(Right(replace(strLicense ,"_"," "), 10), 2) _
& "/" & Left(Right(replace(strLicense ,"_"," "), 8), 4)
Exit Function
End Function
'
=============================================================================
' === Sets the Link Name and File Name into a
Link ===
' ===
ARGUMENTS:
===
' === strFolderPath -
FolderPath ===
' === strLink -
Link ===
' === strName -
Name ===
' === One might use this like
so: ===
' === addLinkage(FolderPath, Link,
Name) ===
'
=============================================================================
Private Function addLinkage(strFolderPath, strLink, strName)
addLinkage = "<a href='" & replace(strFolderPath, "\", "/") &
strLink & "' target='_blank'><span class='fontB'>" & strName & "</
span></a>"
Exit Function
End Function
%>
</td>
</tr>
</table>
</td>
</tr>
<tr bgcolor="#999999">
<td>
<table width="100%" ID="Table2">
<tr>
<td valign="middle" align="right"><!-- #include
file="adobereader_textwhite.txt" --></td>
</tr>
</table>
</td>
</tr>
</table>
<%
Set Navpath = Nothing
Set RootFolder = Nothing
Set ObjFSO = Nothing
Set sf = Nothing
Set files = Nothing
%>
<!-- END YOUR CONTENT ABOVE -->
</td>
</tr>
</table>
</td>
</tr>
</table>
<!-- END "YOUR DEPARTMENT" CONTENT -->
</td>
</tr>
<tr height="15" bgcolor="FEF8E8">
<td></td>
</tr>
<tr>
<td align="center">
<!-- BEGIN DEFAULT FOOTER FOR THE CITY WEBSITE -->
<table width="100%" border="0" align="center" cellpadding="2"
cellspacing="0" bgcolor="#000000" id="corFooter">
<tr valign="top">
<td>
<table cellspacing="0" cellpadding="0" border="0" width="100%"
id="LNDL">
<tr>
<td><font class="font11pxVerdanaFFFFFF" color="#FFFFFF" title="900
East Broad Street, Richmond, Virginia 23219"> 900 East
Broad Street, Richmond, Virginia 23219 (804)646-7000 <a href="/
contact.aspx" class="footer" title="City of Richmond Contact
Information Page.">Contact Us.</a> </font></td>
<td align="right" width="110" rowspan="2"><a href="/"><img src="/
images/footer.image.onecityourcity.jpg" width="110" border="0"
alt="The City of Richmond Virginia." title="The City of Richmond
Virginia."></a></td>
</tr>
<tr>
<td><font class="font11pxVerdanaFFFFFF" color="#FFFFFF"
title="Copyright 2000 to 2005, City of Richmond,
Virginia."> ©2000-2006 City of Richmond, Virginia. All
rights reserved. <a href="/disclaimer.aspx" class="footer" title="The
Privacy Statement, Disclaimer and Terms of Use for this
site.">Privacy, Disclaimer & Terms.</a> </font></td>
</tr>
</table>
</td>
</tr>
</table>
<!-- END DEFAULT FOOTER FOR THE CITY WEBSITE, LNDL --></td>
</tr>
</table>
</td>
</tr>
<!-- End table creating 1px border -->
</table>
</div>
</form>
</body>
</html>