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:


Possibly related posts

11 Responses to “Inconvenient Reusable Content List”

  1. Tweets die vermelden Inconvenient Reusable Content List - Waldek Mastykarz -- Topsy.com Says:

    [...] Dit blogartikel was vermeld op Twitter door Waldek Mastykarz, Planet SharePoint. Planet SharePoint heeft gezegd: Waldek Mastykarz: Inconvenient Reusable Content List http://planetsharepoint.org/1bda56 [...]

  2. Alex Porter Says:

    Thanks for the great post! I'm attempting to use this feature but can't figure out how to enable it on my site. What is the name of the Site Feature that must be enabled? Oddly, my site has the Reusable Content list but no Insert Reusable Content buttons.

    Thanks!
    Alex Porter

  3. Waldek Mastykarz Says:

    @Alex: You need to activate the Publishing Feature on your site.

  4. Neagu Marius Catalin Says:

    Very convenient way but pain in a …when you try to deploy the solution scoped to webapplication not GAC…because you need to deal with cas in manifest file in order to make it functional

  5. Waldek Mastykarz Says:

    @Neagu Marius Catalin: true: that's the whole idea of CAS to make you specify what permissions do you need instead of allowing you to do everything.

  6. Ashutosh Says:

    How can I use reusable contents in Blog Post

  7. Waldek Mastykarz Says:

    @Ashutosh: Have you checked this post http://social.msdn.microsoft.com/Forums/en-US/sharepoint2010general/thread/87e55bbf-ae35-49f3-9c2b-f1c6fea955d1?

  8. Nicolas Bauwens Says:

    Hi,

    Have you already seen the Insert Reusable Content button in another locale ? The items in the list which are normally displayed underneath the button when you click on it are not displayed, but a "More options" choice is displayed instead.

    When you choose that, a pop-up window opens showing you the items in the Reusable Content list, but when you select any of these items, its related content is not inserted into the HTML field.

    Would you have an idea on how to solve that ? :)

    Thanks,
    Nicolas

  9. Waldek Mastykarz Says:

    @Nicolas: No, I haven't noticed that yet. I will see if I can find out anything more about it.

  10. Geoffrey Says:

    I have a sub-site I've created on my SharePoint 2010 server, and I've enabled SharePoint Server Publishing. However, I still don't see the Reusable Content list in my site, under All Content – is there a way to create it?

  11. Waldek Mastykarz Says:

    @Geoffrey: I suggest you compare Features that are activated on a standard Publishing Site and on your site.

Leave a Reply

Security Code:

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS
Copyright © 2007 - 2012 Waldek Mastykarz

Creative Commons License