Tuesday, June 9, 2009

Free Last Modified By/Date From SharePoint

Who Responsible For This Edit!?

With the exception of politicians, most people are in favor of accountability. When it comes to web content management, I'd be the first to agree.

In this post we're going to go over how to get free Last Modified By and Last Modified Date fields on content pages by modifying either select page layouts or master pages. The end product will look like:

Last Modified By/Last Modified Date from SharePoint

What We're Using

We'll be keying off two base fields (Modified, and Modified By) that you can expect to find on pretty much any list you'll ever work with. To prove to you I'm not making things up, feel free to look up the fields yourself (and a tonne of other useful fields) by using SharePoint Explorer for WSS v3.

Modified and Modified By fields displayed in SharePoint Explorer.

Easy Win

Once you find out the names of the fields and their type, the markup to get at these fields is pretty straight forward. We use out of the box SharePoint SPField controls to pull and format the field values. It's of note that we put the ControlMode property to "Display" since we never want these fields to be editable.

Last modified at:
<%@ Register Tagprefix="SharePointWebControls" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<SharePointWebControls:DateTimeField FieldName="Modified" runat="server" ControlMode="Display"/>by
<SharePointWebControls:UserField FieldName="Modified By" runat="server" ControlMode="Display" />

That's pretty much it, throw the above markup into any page layout or master page and you're pretty much done.

But Wait There's More

I'd hate it if you left this post thinking all you'd learned about were two lousy fields and how to display them on a page. There's a tonne of fields that are worth exploring and could potentially add value to your next SharePoint related application.

Example 1: ETL developers could make use of the Created/Created By/Modified/Modified By fields to perform incremental loads when pulling data from the SharePoint object model.

Example 2: UI Developers could use the Comments and Version fields to display the current version and any comments associated with the current version.

The point is that there is yet another lever here to help you get the most functionality out of your next SharePoint related application. Best of all, it's dead simple and doesn't involve a single line of code.



Christian Stahl said...

Hi, that´s cool - this controls are not included via pagefields or contentfields in SPD, never thought you just could use other columns than whats related to the contentype here, nice!

Join www.sharepointdesigners.net

Anonymous said...

Worked perfectly! Thanks!

Anonymous said...

Nice post. Thanks.

santhiswaroop naik said...

boss where we have to add sharepoint webcontrols code please its urgent please reply me

santhiswaroop naik said...


I got it and thank you very much

Knowles Stoner said...

I was trying to get this worked on default.aspx page, then I realized that this works for master pages only. For master page this works great with perfect results.

Inheritx Solutions said...

your aticle very usefull for me....

Sharepoint Development | Sharepoint Developers

A. Bedwell said...

I'm not a programmer so bear with me. I can see the fields great in Designer after adding the code, but they do not show up on our actual intranet pages. Our users want to see this for their teams sites (we have about 24 team sites) and content managers assigned to each site. Any advice would be greatly appreciate

Anonymous said...

Modified by username doesnt display as hyperlink when the page is viewed as anonymous access.. Any Idea how to resolve this issue??

digital signature PDF said...

Very informative post. I sometimes do presentations on SharePoint and was wondering if I could use your Print List example in my presentations and refer my audience to your website for further info.

Unknown said...

It is working but only till the page loads.. After the page is fully loaded "the last modified by and date disappears".

What should be done??

David Mackay said...

We are finding that the control changes the listview selector at the top of the page so it shows Default instead of the ListView title. Any suggestions why this is happening?