Thursday, 13 December 2007

LastModifiedIndicator Kind of Works

SharePoint includes a useful out-of-the box control that can be used to display the date and time a page was last modified. It's not without its hiccups, as I'll describe in a moment, but it's quick and simple to use.

The control in question can be dropped into a page layout or master page using the following syntax:

<PublishingWebControls:LastModifiedIndicator runat="server" />

When the page is served, my local dev server displayed the text below (I'm guessing this display format is relevant to the regional configuration of the server):

12/14/2007 2:24 AM

The LastModifiedIndicator class is derived from WebControl and exposes no additional properties or methods to configure the format decoratively. This would obviously be quite handy because the next best "quality" alternative is probably to implement your own LastModified webpart. The format displayed above will be unsuitable in many cases; although I haven't played with the control's output at any length, a quick and easy hack might be to access the last modified string on the client side and use a bit of JavaScript to reformat its contents using the JavaScript date functions. Definitely not pretty but a little less heavy-handed than building your control or getting in there with some server side code.

You may have noticed a time of 2:24AM in the sample output I listed above; no, I'm not a late night hacker! I actually modified the test page I was working on at 11:24AM on 13 December 2007 but my dev server was telling me I modified it at the unwholesome hour of 2:24, one day in the future. I wish I could do that... or SharePoint would allow me to do that but no luck there so far. Anyway, I haven't tested this solution yet but the legendary Tania down the road from Tourism indicated she got the control to behave by "changing the regional settings of the site and all subsites to Australia and then changing to GMT." I'm not sure exactly what that means but I'm assuming she fiddled with the site settings.

No comments:

Post a comment

Spam comments will be deleted

Note: only a member of this blog may post a comment.