C
CJM
I have an ASP page that lists files and folders in a directory. I'm using a
cookie to record the last time this page was visited, and I intend to show
links that are created/modified from that date minus 30mins to the
present... eg effectively new and modified files:
If DateDiff("n", subfolder.DateLastModified, sLastVisit ) < 30 Then.... etc
On my test machine this mechanism works OK, but on the live server (Win2k,
IIS5) I get some funny behaviour.
I create a new folder, and run the page. The value this expression returns
on XP is 0 and on Win2K is 43200. Refreshing every minute...on XP the value
increases, 1,2,3 etc... On Win2k, it decreases, 43200,43199,43198 etc....
Folders created days ago have values like 37415
The file list is similar:
If DateDiff("n", file.DateLastModified, sLastVisit ) < 30 Then etc....
On the Win2k m/c, a new file returns 43200 again...
Am I missing something?? Do the DateDiff functions behave differently on
different servers (ie different versions of IIS)?
Help!
Thanks
Chris
Bigger Code Snippet (some key settings are stored in an include file):
<%@ Language=VBScript %>
<%
Option Explicit
Response.Expires = 0
Dim folderspec, fso, fold, subfolder, files, file, subfld
Dim sFilter, sStartFolder, sStartPath, sTitle, sContact
Dim aDirs, i, j , sLink
Dim sLastVisit, sCookie, sDateClass, sMaxDiff
'Read LastVisit cookie
sLastVisit = Request.Cookies.Item("QADocs")("LastVisit")
If sLastVisit = "" Then
'sLastVisit = FormatDateTime(Now(),VBShortDate)
sLastVisit = Now()
End If
Response.Write sLastVisit
'Set/Update Cookie
'Response.Cookies("sCookie")("LastVisit") = FormatDateTime(Now(),
VBShortDate)
Response.Cookies.Item("QADocs")("LastVisit") = Now()
%>
<!-- #include file="config.asp" -->
<%
'Recover subfolder name if available
subfld = Request.Querystring("sub")
subfld = subfld & "/"
'create full folder path
folderspec = Replace(sStartPath & subfld, "/", "\")
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title><%=sTitle%></title>
<link type='text/css' rel='stylesheet' href='Quality.css'>
</head>
<body>
<div id='header'>
<h2><%=sTitle%></h2>
</div>
<div id='outer'>
<p>Note: Files or folders that have been added or modified since your last
visit have their dates shown <span class="new">like this.</span></p>
<table id='tbls'>
<tr id="breadcrumbs">
<td colspan="2">
<%
Response.Write "<a href='./quality.asp'>" & sStartFolder & "</a>"
aDirs = Split(subfld,"/")
For i = 1 to UBound(aDirs)
Response.Write " > <a href='"
sLink = ""
For j = 1 to i
sLink=sLink & "/" & aDirs(j)
Next
Response.Write "./quality.asp?sub=" & sLink
Response.Write "'>" & aDirs(i) & "</a>"
Next
%>
</td>
</tr>
<tr>
<td>
<!-- Folders table -->
<table class="fld">
<colgroup class="lhs" />
<colgroup class="rhs" />
<tr>
<td class="title">Folder Name</td>
<td class="title">Last Modified</td>
</tr>
<%
'Create FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
'Loop through Folders
Set fold = fso.GetFolder(folderspec)
for each subfolder in fold.subFolders
'ignore system or hidden folders - signified by "_"
If Left(subfolder.name,1) <> "_" Then
If DateDiff("n", subfolder.DateLastModified, sLastVisit ) < sMaxDiff Then
sDateClass = "new"
Else
sDateClass = ""
End if
%>
<tr>
<td><a class="folder"
href='quality.asp?sub=<%=subfld &
subfolder.name%>'><%=subfolder.name%>...</a></td>
<td
class="<%=sDateClass%>"><%=FormatDateTime(subfolder.DateLastModified,
VBShortDate)%><%= "..." & DateDiff("n", subfolder.DateLastModified,
sLastVisit)%></td>
</tr>
<%
End if
next
%>
</table>
</td>
<td>
<!-- Files table -->
<table class="fil">
<colgroup class="lhs" />
<colgroup class="rhs" />
<tr>
<td class="title">File Name</td>
<td class="title">Last Modified</td>
</tr>
<%
'Loop through Files
set files = fold.files
for each file in files
If Instr(1, sFilter, lcase(right(file.name,3))) Then
If DateDiff("n", file.DateLastModified, sLastVisit ) < sMaxDiff Then
sDateClass = "new"
Else
sDateClass = ""
End if
%>
<tr>
<td><a class="file" href='.<%=subfld &
file.name%>'><%=file.name%></a></td>
<td
class="<%=sDateClass%>"><%=FormatDateTime(file.DateLastModified,
VBShortDate)%><%= "..." & DateDiff("n", file.DateLastModified,
sLastVisit )%></td>
</tr>
<%
End if
Next
%>
</table>
</td>
</tr>
</table>
</div>
<p>If you have any queries or you think this page is not functioning
correctly contact <%=sContact%>.</p>
</body>
</html>
cookie to record the last time this page was visited, and I intend to show
links that are created/modified from that date minus 30mins to the
present... eg effectively new and modified files:
If DateDiff("n", subfolder.DateLastModified, sLastVisit ) < 30 Then.... etc
On my test machine this mechanism works OK, but on the live server (Win2k,
IIS5) I get some funny behaviour.
I create a new folder, and run the page. The value this expression returns
on XP is 0 and on Win2K is 43200. Refreshing every minute...on XP the value
increases, 1,2,3 etc... On Win2k, it decreases, 43200,43199,43198 etc....
Folders created days ago have values like 37415
The file list is similar:
If DateDiff("n", file.DateLastModified, sLastVisit ) < 30 Then etc....
On the Win2k m/c, a new file returns 43200 again...
Am I missing something?? Do the DateDiff functions behave differently on
different servers (ie different versions of IIS)?
Help!
Thanks
Chris
Bigger Code Snippet (some key settings are stored in an include file):
<%@ Language=VBScript %>
<%
Option Explicit
Response.Expires = 0
Dim folderspec, fso, fold, subfolder, files, file, subfld
Dim sFilter, sStartFolder, sStartPath, sTitle, sContact
Dim aDirs, i, j , sLink
Dim sLastVisit, sCookie, sDateClass, sMaxDiff
'Read LastVisit cookie
sLastVisit = Request.Cookies.Item("QADocs")("LastVisit")
If sLastVisit = "" Then
'sLastVisit = FormatDateTime(Now(),VBShortDate)
sLastVisit = Now()
End If
Response.Write sLastVisit
'Set/Update Cookie
'Response.Cookies("sCookie")("LastVisit") = FormatDateTime(Now(),
VBShortDate)
Response.Cookies.Item("QADocs")("LastVisit") = Now()
%>
<!-- #include file="config.asp" -->
<%
'Recover subfolder name if available
subfld = Request.Querystring("sub")
subfld = subfld & "/"
'create full folder path
folderspec = Replace(sStartPath & subfld, "/", "\")
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title><%=sTitle%></title>
<link type='text/css' rel='stylesheet' href='Quality.css'>
</head>
<body>
<div id='header'>
<h2><%=sTitle%></h2>
</div>
<div id='outer'>
<p>Note: Files or folders that have been added or modified since your last
visit have their dates shown <span class="new">like this.</span></p>
<table id='tbls'>
<tr id="breadcrumbs">
<td colspan="2">
<%
Response.Write "<a href='./quality.asp'>" & sStartFolder & "</a>"
aDirs = Split(subfld,"/")
For i = 1 to UBound(aDirs)
Response.Write " > <a href='"
sLink = ""
For j = 1 to i
sLink=sLink & "/" & aDirs(j)
Next
Response.Write "./quality.asp?sub=" & sLink
Response.Write "'>" & aDirs(i) & "</a>"
Next
%>
</td>
</tr>
<tr>
<td>
<!-- Folders table -->
<table class="fld">
<colgroup class="lhs" />
<colgroup class="rhs" />
<tr>
<td class="title">Folder Name</td>
<td class="title">Last Modified</td>
</tr>
<%
'Create FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
'Loop through Folders
Set fold = fso.GetFolder(folderspec)
for each subfolder in fold.subFolders
'ignore system or hidden folders - signified by "_"
If Left(subfolder.name,1) <> "_" Then
If DateDiff("n", subfolder.DateLastModified, sLastVisit ) < sMaxDiff Then
sDateClass = "new"
Else
sDateClass = ""
End if
%>
<tr>
<td><a class="folder"
href='quality.asp?sub=<%=subfld &
subfolder.name%>'><%=subfolder.name%>...</a></td>
<td
class="<%=sDateClass%>"><%=FormatDateTime(subfolder.DateLastModified,
VBShortDate)%><%= "..." & DateDiff("n", subfolder.DateLastModified,
sLastVisit)%></td>
</tr>
<%
End if
next
%>
</table>
</td>
<td>
<!-- Files table -->
<table class="fil">
<colgroup class="lhs" />
<colgroup class="rhs" />
<tr>
<td class="title">File Name</td>
<td class="title">Last Modified</td>
</tr>
<%
'Loop through Files
set files = fold.files
for each file in files
If Instr(1, sFilter, lcase(right(file.name,3))) Then
If DateDiff("n", file.DateLastModified, sLastVisit ) < sMaxDiff Then
sDateClass = "new"
Else
sDateClass = ""
End if
%>
<tr>
<td><a class="file" href='.<%=subfld &
file.name%>'><%=file.name%></a></td>
<td
class="<%=sDateClass%>"><%=FormatDateTime(file.DateLastModified,
VBShortDate)%><%= "..." & DateDiff("n", file.DateLastModified,
sLastVisit )%></td>
</tr>
<%
End if
Next
%>
</table>
</td>
</tr>
</table>
</div>
<p>If you have any queries or you think this page is not functioning
correctly contact <%=sContact%>.</p>
</body>
</html>