I need help with the following code. I've inherit this setup and did my best to add sorting and links myself, but I still have the following problems:
1. I wanted to make one file (listCollateral.asp) to get the files from one of the customCollateral folders when a link on another page calls for it. (e.x. 'http://www.examplesite.biz/distributors/listCollateral.asp?list=ads').
Right now it displays the list of files in the listed folder but as soon as you sort - it goes back to the root folder and displays those files.
2. How can I only make the file names links? Right now everything is a link (file type, file size, date modified).
3. Is there a better/easier way of doing the same thing in a Microsoft environment without recreating all the other webpages? It is setup this way so non-technical people can just upload a new file to one of the customCollateral folders and the webpage directory immediately updates.
See the full code below. Thank you in advance.
<%@ Language=VBScript %>
<%
Response.Expires = 0
Response.Expiresabsolute = Now() - 1
Response.AddHeader "pragma","no-cache"
Response.AddHeader "cache-control","private"
Response.CacheControl = "no-cache"
%>
<HTML>
<HEAD>
<TITLE>Custom Collateral</TITLE>
<style type="text/css">
a {
font-size: 12px;
color: #0b2d60;
font-family: Arial, Helvetica, sans-serif;
}
a:link {
text-decoration: none;
font-family: Arial, Helvetica, sans-serif;
}
a:visited {
text-decoration: none;
color: #0b2d60;
font-family: Arial, Helvetica, sans-serif;
}
a:hover {
text-decoration: none;
color: #999;
font-family: Arial, Helvetica, sans-serif;
}
a:active {
text-decoration: none;
color: #FFF;
font-family: Arial, Helvetica, sans-serif;
}
</style>
</HEAD>
<BODY LEFTMARGIN="0" TOPMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0">
<SCRIPT TYPE='text/javascript'>
function Go(){return}
</SCRIPT>
<NOSCRIPT>
<FONT COLOR="#FFFFFF">Please enable JavaScript within your Internet browser to correct display issues with this page.</FONT>
</NOSCRIPT>
<%
'code modified from http://www.4guysfromrolla.com/aspfaqs/ShowFAQ.asp?FAQID=118
' Specify one of these constants for "sortBy"...
CONST FILE_NAME = 0
'CONST FILE_EXT = 5 'changed to 5
CONST FILE_TYPE = 2
CONST FILE_SIZE = 3
'CONST FILE_CREATED = 4
CONST FILE_MODIFIED = 1 'changed to 1
'CONST FILE_ACCESSED = 6
' get requested sort order, if not first time here...
' (forward by name is default)
req = Request("sortBy")
If Len(req) < 1 Then sortBy = 0 Else sortBy = CInt(req)
req = Request("priorSort")
If Len(req) < 1 Then priorSort = -1 Else priorSort = CInt(req)
'
' did user ask for same sort? to reverse the order?
' but if so, then zap priorSort so clicking again will do forward!
If sortBy = priorSort Then
reverse = true
priorSort = -1
Else
reverse = false
priorSort = sortBy
End If
' now start the *real* code...
'
listing = request.querystring("list")
select case listing
case "Latest"
header = "Latest"
case "11x17brochures"
header = "11 x 17 Brochures"
case "85x11brochures"
header = "8 1/2 x 11 Brochures"
case "ads"
header = "Advertisements"
case "Energy Efficient"
header = "Energy Efficient"
case "banners"
header = "Banners"
case "Spanish Brochures"
header = "Spanish Brochures"
case "newsletters"
header = "News Letters"
case "catPages"
header = "Catalog Pages"
case "misc"
header = "Miscellaneous"
case "pptpresentation"
header = "Power Point Presentation"
case "posters"
header = "Posters"
case "salesFlyers"
header = "Sales Flyers"
case "triFold"
header = "Tri-Folds"
case "massMailers"
end select
theFolder = "C:\publish\wwwroot\v2008\distributors\customCollateral\" & listing
webShare = "customCollateral\" & listing &"/"
linkTarget = "_blank"
Set fso = CreateObject("Scripting.FileSystemObject")
Set theCurrentFolder = fso.GetFolder(theFolder)
Set curFiles = theCurrentFolder.Files
'
' And now a loop for the files
'
Dim theFiles( )
ReDim theFiles( 500 ) ' arbitrary size!
currentSlot = -1 ' start before first slot
' We collect all the info about each file and put it into one
' "slot" in our "theFiles" array.
'
For Each fileItem in curFiles
fname = fileItem.Name
'fext = InStrRev( fname, "." )
'If fext < 1 Then fext = "" Else fext = Mid(fname,fext+1)
ftype = fileItem.Type
fsize = fileItem.Size
' fcreate = fileItem.DateCreated
fmod = DateValue(fileItem.DateLastModified)
' faccess = fileItem.DateLastAccessed
currentSlot = currentSlot + 1
If currentSlot > UBound( theFiles ) Then
ReDim Preserve theFiles( currentSlot + 99 )
End If
' note that what we put here is an array!
theFiles(currentSlot) = Array(fname, ftype, fsize, fmod) 'do not use ftext, fcreate, faccess
Next
'
' files are now in the array...
'
' As noted, it is actually an ARRAY *OF* ARRAYS. Which makes
' picking the column we will sort on easier!
'
' ...size and sort it...
fileCount = currentSlot ' actually, count is 1 more, since we start at 0
ReDim Preserve theFiles( currentSlot ) ' really not necessary...just neater!
' First, determine which "kind" of sort we are doing.
' (VarType=8 means "string")
'
If VarType( theFiles( 0 )( sortBy ) ) = 8 Then
If reverse Then kind = 1 Else kind = 2 ' sorting strings...
Else
If reverse Then kind = 3 Else kind = 4 ' non-strings (numbers, dates)
End If
'
' A simple bubble sort for now...easier to follow the code...
'
For i = fileCount TO 0 Step -1
minmax = theFiles( 0 )( sortBy )
minmaxSlot = 0
For j = 1 To i
Select Case kind ' which kind of sort are we doing?
' after the "is bigger/smaller" test (as appropriate),
' mark will be true if we need to "remember" this slot...
Case 1 ' string, reverse...we do case INsensitive!
mark = (strComp( theFiles(j)(sortBy), minmax, vbTextCompare ) < 0)
Case 2 ' string, forward...we do case INsensitive!
mark = (strComp( theFiles(j)(sortBy), minmax, vbTextCompare ) > 0)
Case 3 ' non-string, reverse ...
mark = (theFiles( j )( sortBy ) < minmax)
Case 4 ' non-string, forward ...
mark = (theFiles( j )( sortBy ) > minmax)
End Select
' so is the current slot bigger/smaller than the remembered one?
If mark Then
' yep, so remember this one instead!
minmax = theFiles( j )( sortBy )
minmaxSlot = j
End If
Next
' is the last slot the min (or max), as it should be?
If minmaxSlot <> i Then
' nope...so do the needed swap...
temp = theFiles( minmaxSlot )
theFiles( minmaxSlot ) = theFiles( i )
theFiles( i ) = temp
End If
Next
' Ta-da! The array is sorted!
'
%>
<FORM Name="doSort" Method="Get">
<INPUT Type=Hidden Name=priorSort Value="<% = priorSort %>">
<INPUT Type=Hidden Name=sortBy Value="-1">
</FORM>
<SCRIPT Language="JavaScript">
function reSort( which )
{
document.doSort.sortBy.value = which;
document.doSort.submit( );
}
</SCRIPT>
<CENTER>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="100%">
<TR>
<TD WIDTH="60%" CLASS="welcome">Marketing Materials<BR>
<%= header %>
</TD>
</TR>
</TABLE>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR BGCOLOR="#eeeeee">
<TH style="font-size: 14px; text-align: left; font-family: Arial, Helvetica, sans-serif; color: #FFF; font-weight: bold;"><a HREF="java<!-- no -->script:reSort(0);">File</A>File</A></TH>
<TH style="font-size: 14px; text-align: left; font-family: Arial, Helvetica, sans-serif; color: #FFF; font-weight: bold;"><a HREF="java<!-- no -->script:reSort(2);">Type</A></TH>
<TH style="font-size: 14px; text-align: left; font-family: Arial, Helvetica, sans-serif; color: #FFF; font-weight: bold;"><a HREF="java<!-- no -->script:reSort(3);">Size</A></TH>
<TH height="20px" style="font-size: 14px; text-align: left; font-family: Arial, Helvetica, sans-serif; color: #FFF; font-weight: bold;"><a HREF="java<!-- no -->script:reSort(1);">Modified</A></TH>
</TR>
<%
' With the array nicely sorted, this part is a piece of cake!
For i = 0 To fileCount
Response.Write "<TR>" & vbNewLine
For j = 0 To UBound( theFiles(i) )
Response.Write "<TD><A HREF='" & webShare & theFiles(i)(j) & "' target='" & linkTarget & "'>" & theFiles(i)(j) & "</A></TD>" & vbNewLine
Next
Response.Write "</TR>" & vbNewLine
Next
%>
</TABLE>
</BODY>
</HTML>