Inconvenient Reusable Content List

One of the great capabilities of SharePoint Server is the ability of including reusable content: standard snippets of HTML which you can use in different places over and over again without having to copy & paste it. The great thing about Reusable Content is that you have the option to insert a reference instead of the copy of the content so that if the content snippet ever changes, you won’t have to manually check every single page in your site to ensure that the content is correct: SharePoint will do this for you automatically. While this piece of functionality is really great you wouldn’t believe how inconvenient it is to get to this list to add new content snippets in there.

Two faces of the Reusable Content List

From the Content Management point of view, the Reusable Content List is just an ordinary List located in the Root Web of your Site Collection. You can navigate to it using the View All Site Content option. Nothing special about it here.

Reusable Content List in the View All Site Content view

If you enable using Reusable Content on your Site Collection, an option will appear in the Rich Text Editor allowing you to insert snippets of Reusable Content into the editor.

Insert Reusable Content option in the Rich Text Editor in SharePoint Server 2010

Given the benefits Reusable Content gives to the content editors it is a crime not to use it or at least not to educate the users about it.

From the code perspective the Reusable Content List – the List which stores all the snippets of reusable contents resembles a lot a system List – there is no easy way to get it…

The challenges

First of all let me note that both the Title and the Name of the Reusable Content List depend on the locale that you are using. So if you’re developing a Solution for a single locale, you might get away with hard coding the name of the list. If you however work on a real Solution that should support you-never-know-which-language, you have some extra work to do.

As I mentioned before the Reusable Content List resembles a hidden List from the code perspective. There is no public method available to retrieve either the instance, the name or the ID of this List. There are some internal properties but as the name says: it’s not something you can use in your code.

So how can you do it in a reliable or an acceptably-reliable way?

The solution

Probably the only reliable way of retrieving a reference to the Reusable Content List is by retrieving its ID and then getting a reference to this List using this ID.

The ID of the Reusable Content List is stored in the SPWeb.AllProperties property called _ReusableContentListId:

string reusableContentListIdPropertyName = "_ReusableContentListId";  
SPWeb rootWeb = SPContext.Current.Site.RootWeb;  
if (rootWeb.AllProperties.ContainsKey(reusableContentListIdPropertyName))  
    Guid reusableContentListId = new Guid(rootWeb.AllProperties[reusableContentListIdPropertyName] as string);

Using the retrieved GUID you can now get a reference to the Reusable Content List to add your custom content snippets.

As I mentioned before this is only an acceptably reliable way as the name of the internal property that stored the ID of the Reusable Content List isn’t publicly available in the API and might be changed in the future versions of SharePoint. So if you’re using this functionality in your Solution, it adds an additional point to your checklist before upgrading to the next version.

Technorati Tags: SharePoint


comments powered by Disqus