SharePoint, as usual, offers lots of ways to do things. This time, I’m going to show how one can get a list of the last modified contents, in any SharePoint version and edition.
We’ll use our good friends DataFormWebPart and SPDataSource, together with some XSLT and some nice tricks. We will be able to specify the number of items to return through the query string, otherwise it will default to 5. I’m going to keep it simple, but you can certainly improve it.
We add a DataFormWebPart with an inline SPDataSource that uses DataSourceMode of CrossList. This allows querying multiple lists at once. The actual query is specified in the SelectCommand property. In this case, I am specifying it as:
What it means is:
Search recursively all subsites (Scope=’Recursive’);
Only search lists and document libraries of type Wiki Page Library (ServerTemplate=’119’);
Limit the returned results to the value passed in parameter TopN (RowLimit);
Only return files (FSObjType = 0) containing .aspx in its name;
Return fields List Title (ListProperty Name=’Title’), List ID (ListProperty Name=’ID’), Object Type (FSObjType), ID, Title, File Location (FileRef), File Directory (FileDirRef), File Name (FileLeafRef), Last Modification User (Editor) and Last Modification Timestamp (Modified);
Order by the List Title.
The markup for the DataFormWebPart is as follows:
The ParameterBindings section includes an entry that gets a TopN parameter from the query string, and if one is not there, sets the default to 5. This parameter is passed to the SPDataSource through a DataFormParameter.
While we are iterating through the results, we call the ddwrt:NameChanged extension function upon the value of ListProperty.Title to check if we have changed to a new list, in which case, we add a new row with just its name. Inside each list, items are obtained where they match the list and sorted by the ddwrt:FormatDateTime function according to its last modification timestamp.
I think that’s it. Hope you find it useful.