Active Server Corner
Quick Site Search
What's Inside
Home
Activity
Books
Excerpts
In-Depth
CodeLibrary
Columns
ActiveTalk
COMSutra
Cornered!
My 3 Cents
Square ONE
Downloads
Events
FAQ's
Jobs
Search
Tools
Product Reviews
Tutorials
Site Info
About Us
Advertising Info
Contact Us
Privacy Policy
Terms of Use
Write for Us
  CodeLibrary @ Active Server Corner   The source for source code

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()
  ' Local variables
  Dim loFs, lsFile, lsPath, loFile, ldLast

  ' Create an instance of FileSystemObject object
  Set loFs = CreateObject("Scripting.FileSystemObject")

  ' Get the logical path of the current file
  ' (i.e. the file in which this code runs)

  lsFile = Request.ServerVariables("SCRIPT_NAME")

  ' Get the physical path of the file
  lsPath = Server.MapPath(lsFile)

  ' Get a handle/pointer to this file
  Set loFile = loFs.GetFile(lsPath)

  ' Get the "Last Modified" property of this file
  ldLast = loFile.DateLastModified

  ' Release the objects
  Set loFile = Nothing
  Set loFs = Nothing

  ' Write out the date in the long date
  ' format e.g. "MM/DD/YY"

  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.

 






Copyright © 1997-2000 Active Server Corner. All rights reserved.

Sponsored by Coastline Web Hosting in Santa Barbara, California