Omicron Llama

Coding all day, every day.

SharePoint – "New" Image Graphic – Identify New Content to Users

If you’re displaying a list of items in a Data View Web Part, you might want to visually show to your users if the item displayed is a “new” item. An extra little flourish to enhance the user experience.

Let us first decide that a item should be flagged as “new” if it was created within the past 7 days (though for busier lists, you might want to reduce that down to a couple of days, or even hours!).

Select the field in our DVWP that you want to show the new icon and jump back to Code View. Find the value-of statement which prints this.

Just after the value-of statement, create an if statement to find out if this item was Created in the past 7 days, and if so, display the new icon from the 12-hive layouts library.

The essence behind our if test is simply convert “Today()” into a number composing of yyyymmdd (so today would be 20100414 and do the same with the list item’s Created date (like 20100410), subtract the latter from the former and see if we get a number less than 7.

Postscript:

As raised by Marc Anderson in the comments for this post, this method may introduce odd behaviour at month end boundaries. His blog post suggests using the ddwrt-namespace method “IfNew” (which I didn’t know until I read that! Learn something new every day!) which uses server-set variable 2 days for new items (which can be changed). The method in his blog post is definitely more concise and easier to read. You may want differing definitions of “New” in different lists throughout your site – so the method in this post may be a starting point for doing so.

Postpostscript:

A good point was raised by Brian on the community support website “SharePoint Overflow“:

This looks like it will work. A side note, you must be careful about the RegionalSettings for the web and how the SPListItem returns it’s “Created” (and also “Modified”) fields. Comparing them to DateTime.Now is probably not valid if your site is accessed by users not in the TimeZone specified for the SPWeb. See this: msdn.microsoft.com/en-us/library/ms197282.aspx and this¬†http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splistitem.aspx.


Taken from the question thread found at: http://www.sharepointoverflow.com/questions/5322/splistitem-isnew-functionality

2 thoughts on “SharePoint – "New" Image Graphic – Identify New Content to Users

Leave a Reply

Your email address will not be published. Required fields are marked *