Including "Last Modified" date in ASP Files
by Manohar Kamath
July 31st, 1999
The "Last Modified" date on any web page is indicative
of how dynamic that page is. By dynamic I don't mean how dynamically it is created, but
when the page itself was modified. In plain HTML files this could mean when the content
was changed, and in ASP files this could also suggest when the logic of the page was
changed. Although it is good to have this date on every page on the site, it is highly
recommended that you have this on pages that serve as "portals" or
"gateways" - pages like the default page, "what's new" page, etc.
The following snippet of code will show how you can do this, in
VBScript.
<SCRIPT LANGUAGE=VBScript RUNAT=SERVER>
Function FileLastMod()
Dim loFs, lsFile, lsPath, loFile, ldLast
Set loFs = CreateObject("Scripting.FileSystemObject")
lsFile = Request.ServerVariables("SCRIPT_NAME")
lsPath = Server.MapPath(lsFile)
Set loFile = loFs.GetFile(lsPath)
ldLast = loFile.DateLastModified
Set loFile = Nothing
Set loFs = Nothing
FileLastMod = CStr(FormatDateTime(ldLast, 2))
End Function
</SCRIPT>
Just copy this code into any ASP page you want, or even copy this
into an include file and include that file and call the function something like
<% Response.Write ("<br>Last Modified " &
FileLastMod()) %>
The result is something like:
Last Modified 1/1/99
You may ask why I wrote this function within <script> tags?
Just incase you were to call this function from a non-VBScript page (Javascript,
PerlScript, etc.), it shouldn't make a difference, that's why.
|