Document library web part – New file indicator

   —   
This article describes how to enable/implement a “New file” indicator functionality in the Document library web part. This functionality should allow users to see which files are new, i.e. which files have been uploaded within a defined time span.
When using the Document library web part (you can see an example of it on Intranet sample site), you may want to distinguish newly uploaded documents from older documents, so that users can easily see which of them are new. The time span can be set according to your requirements. It can be declared in minutes or hours. When the proper time passes, the “New file” indicator disappears.

At first, let´s have a look at the Document library web part file, which is placed in the usual location for Kentico web parts: <project folder>/CMSWebParts/DocumentLibrary/DocumentLibrary.ascx

You can see that the following control is registered within the web part:
<project folder>/CMSModules/DocumentLibrary/Controls/DocumentLibrary.ascx

When you navigate to the control, you can see a UniGrid control used for displaying particular items by the Document library web part.

If you have a look at the gridDocuments_OnDataReload() method in the code-behind, you will see what columns are included in the given DataSet.

string columns = SqlHelperClass.MergeColumns(DocumentHelper.GETDOCUMENTS_REQUIRED_COLUMNS, "NodeAlias, NodeGUID, DocumentName, DocumentCulture, DocumentModifiedWhen, Published, DocumentType, DocumentWorkflowStepID, DocumentCheckedOutByUserID, SiteName, NodeSiteID, NodeOwner, FileAttachment, DocumentName AS PublishedDocumentName, DocumentType AS PublishedDocumentType");

You can see that the DocumentModifiedWhen column is already included. In fact, this value is displayed in UniGrid by default. This value is updated when you upload a new document, so you can simply compare the value in DocumentModifiedWhen with the current time. If these values match (with some tolerance), you can add any marker or image to the given file.


For example:

Line 919 (5.5R2):

//Get DateTime value from DataSet
DateTime mod = (DateTime)drv["DocumentModifiedWhen"];

// Get TimeSpan
TimeSpan ts = DateTime.Now - mod;

Line 952

//Set if condition in a way that documents newer than 12 hours are marked as new
if (ts.Hours < 12)
{

// set new icon
string sIndicator = "<img src=\"~/App_Themes/IntranetPortal/Images/icon-new.gif\">";
attachmentName = sIndicator + " " + attachmentName;

}

Of course, you can modify parameters like the time span (Minutes/Hours) or “New indicator,” which can be text or an image. In my example, icon-new.gif is custom file placed in the App_Themes folder. It is not part of the standard installation, but you can use any custom file or download it from the Internet.

The result looks like this (please note the “New” indicator):

 
-rm-


See also:

Applies to: Kentico CMS 5.5R2
Share this article on   LinkedIn