Adding 'Last Updated' To Footer in ASP.NET

In the ‘old’ Classic ASP days, we could use the FileSystemObject, in an include file, to automatically display a ‘Last Modified’ section. This possibility has not gone away, with the advent of ASP.Net. In fact, using the System.IO namespace, there are a couple of ways to do it.

You’ll probably recognize this Classic ASP code, using the FileSystemObject:

<% Dim oFS Dim sPath Dim oFile Set oFS = Server.CreateObject("Scripting.FileSystemObject") sPath = Request.ServerVariables("Path_Translated") Set oFile = oFS.GetFile(sPath) response.write "Last Updated " & oFile.DateLastModified & _ " © 2004 YourCompanyName - All rights reserved" Set oFile = Nothing Set oFS = Nothing %>

Now, we merely import the System.IO namespace, add a label to the page and we change it to this:

Dim sPath as String = Request.ServerVariables("Path_Translated") Dim dt As DateTime = File.GetLastWriteTime(sPath ) lblBottom.Text= "Last Updated " & dt.ToString & _ " / ©2004 YourCompanyOrWebSiteName / All rights reserved"

There are a couple of ways you can do this, also. One way is to create a Footer User Control. As you probably know, User Controls are new wtih ASP.net. I won’t go into an explanation of User Controls here, since another Code Sample on this site shows how to create a simple header or footer User Control

.

The other way might surprise you. Most people are under the impression that Include Files have simply gone away, with the advent of ASP.Net. However, this is not true. There are some things that won’t work in an include file, but in general, it can still be used.

With the above sample, all that would be needed is to create a new ASPX file, to use as your footer. In that file, create a script block and Page_Load routine, just as you would with any other ASP.Net page which uses inline coding. You would put any text or formatting you need, however you need it, and then, put a label where you’d want this to appear. Here is a sample:

<%@ Import Namespace="System.IO" %> <script language="VB" Runat="server"> Dim sPath as String Dim dt as DateTime Sub Page_Load(Source as Object, E as EventArgs) sPath = Request.ServerVariables("Path_Translated") dt = File.GetLastWriteTime(sPath ) lblBottom.Text= "Last Updated " & dt.ToString & _ " / ©2004 YourCompanyName / All rights reserved" End Sub </script> <div align="center"><Font Size=2>Please, email your questions or comments to : <a href="mailto:questions@yourSite.com?Subject=Questions"> (questions@yourSite.com)</a></Font> <BR> <font Size="1"> <asp:Label ID="lblBottom" Runat="server" /> </font></div>

That’s basically it – - as you can see, just like other samples and tutorials on this site, it’s much simpler than you might have thought!
Happy coding!

Related Posts:

  • No Related Posts
Twitter Digg Delicious Stumbleupon Technorati Facebook Email

No comments yet... Be the first to leave a reply!