Custom document reports using OOTB SharePoint

There is a useful feature of SharePoint that provides site collection wide reporting across documents (and items). I’m referring to ‘Site Content and Structure Reports’ and it allows you to view a handful of OOTB reports as well as create custom reports (al beit somewhat limited). You may not want to provide access to this page for many users but it can be a handy IT feature if nothing else. I have an example of a “documents checked out to any user” report at the end of this blog.

The Content and Structure page can be found under Site Settings in SharePoint 2013 [or in the Site Actions drop down in SharePoint 2010]
The Content and Structure page can be found under Site Settings in SharePoint 2013 [or in the Site Actions drop down in SharePoint 2010]

The default reports are listed in the next image and some can be quite useful like ‘Checked out to me’ and ‘My tasks’ although often a customised solution has more elegant approaches to displaying this information elsewhere. The good bit is that it is very easy to make your own assuming you know CAML.

The reports can be run using the View menu on the Content and Structure page
The reports can be run using the View menu on the Content and Structure page

There’s a link to the list of these report definitions from the site collection root site (/Reports%20List/AllItems.aspx). Here you can create new report definitions just by adding a new item to the list. You merely need to define the CAML which will then return results from every library/list in site collection.

The set of Content and Structure report items the come with SharePoint
The set of Content and Structure report items the come with SharePoint

As an example, I have created a new report to return all checked out documents no matter who they are checked out to by using the following CAML:
<Where><IsNotNull><FieldRef Name="CheckoutUser" LookupId="TRUE"/></IsNotNull></Where>

Report: Checked out to anyone
Report: Checked out to anyone

It is important to note that you should leave both of the ‘Resource Id’ column blank. If you populate these columns with valid resource Ids then the correspoding resources will overwrite the reports CAML and description.
Also if you would like to restrict the query to a specific sub-set of list types then you can use the ‘CAML List Type’ field to enter a list definition ID (a full list of the defaults can be found here) like so:
<Lists ServerTemplate="101"/>

Another handy use of this is to create a report all of all pages awaiting approval. This can be achievd with a CAML List Type of: <Lists ServerTemplate="850"/> and a CAML Query of: <Where><And><Eq><FieldRef ID="{fdc3b2ed-5bf2-4835-a4bc-b885f3396a61}"></FieldRef><Value Type="Number">3</Value></Eq><IsNull><FieldRef Name="CheckoutUser" LookupId="TRUE"/></IsNull></And></Where>

Note the List Template ID of 850 representing Pages Library.

Hope you found this useful.

Breadcrumb (SiteMapPath) is wrong after moving a site

I have been finding that when moving a site (SPWeb) to a different location in the site hierarchy of a site collection that the breadcrumb would often (not always) be incorrect once the site had been moved.

If you didn’t know, SiteMapProviders are cached in the SharePoint object cache. I’ll put the sporadic nature of the issue down to the natural refresh cycle of the object cache but honestly I’m not completely sure why it doesn’t go wrong all the time. The important bit is that there is way to ensure that the breadcrumb is refreshed correctly every time. For the sake of completeness, here is the SiteMapPath control with its SiteMapProvider property set to CurrentNavSiteMapProviderNoEncode from the custom master page (if you want to read more about this you could start here):

SiteMapPath

If you are suffering this issue I suspect that mentioning the object cache was enough to put you on the right path but I’ll spell it out just in case.

If you run a few lines of code in a WebMoved event receiver (I blogged briefly about attaching these here) you force the object cache to be refreshed whenever a site is relocated. Be warned that if you have a site that leverages the object cache (e.g. use of the cross-list query object, or the content query web part which utilises it) that these operations will need to re-cache and may have some performance impact.

SiteCacheSettingsWriter writer=new SiteCacheSettingsWriter(site);
writer.SetFarmCacheFlushFlag();
writer.Update();

You may need to fetch the SPSite object that is passed into the constructor from within an elevated privileges block to ensure the current user is allowed to perform this action. Obviously that depends on expected audience for this action.

SPC14 Sessions Reviewed (by someone else!)

I have been spending a little time deciding which sessions from the SharePoint Conference 2014 (SPC14) I want to watch over the coming weeks. Unfortunately I was unable to attend this year, but I know from previous years that it truly is an amazing conference with so much great content (and it’s in Vegas baby!).

Anyway, during my searching I came across a blog post (by CJG) which reviews (albeit briefly) every single session. Whaaaa..? I can’t confirm how valid his appraisals are as I’m still yet to get stuck in, however I was so impressed that I had to post a reference to the blog. You can find it here.

SharePoint Conference 2014
SharePoint Conference 2014