Template library on site templates

Jul 23, 2009 at 9:57 AM

1. I designed a site in which I used your solution on some libraries.

2. Then I saved this site as a template.

3. When I created a new site on this template, the feature "Template library" is available but not set up so as I defined on the original site.

Is it possible to save these "Template library" settings to the "Site template" in such a way that the libraries on the created site will have templates active at once (so as it is on the original site).

Thanks for your answer in advance.

Jul 23, 2009 at 11:35 AM

The template library connector settings are currently saved in the doclib's root folder property bag. This is present in exported site templates, but SharePoint does not restore them when you make sites.

I've contemplated several fixes to the problem, and I've sort of landed on using the web's propertybag, rather than the folder's property bag, but this hasn't been implemented yet. While using the webprops would certainly work, I find it rather hairy to store doclib related settings outside the actual doclib. Any input on the issue would be appreciated.

Sep 10, 2009 at 12:48 PM


I looked at your code a bit, and propose following changes, so it could work with saving site as template.

Changes are made to the class TemplateLibraryConnectorSettings. I modified the existing methods, and simply added new key (NEW_PROPERTY_KEY) with root folder name so it would be uniquely identified at the current site. I left the loading and saving to existing properties for backwards compatibility.


Have fun :)


public static TemplateLibraryConnectorSettings LoadFromList(SPList list)
            string NEW_PROPERTY_KEY = PROPERTY_KEY + "_" + list.RootFolder.Name;
            // See if the property bag contains the settings' key
            if (list.ParentWeb.Properties.ContainsKey(NEW_PROPERTY_KEY))
                return TinyXmlSerializer.Deserialize<TemplateLibraryConnectorSettings>(
                    list.ParentWeb.Properties[NEW_PROPERTY_KEY] as string);
            else if (!list.RootFolder.Properties.ContainsKey(PROPERTY_KEY))
                return null;
                   list.RootFolder.Properties[PROPERTY_KEY] as string);

        public static void SaveToList(SPList list, TemplateLibraryConnectorSettings settings)
            string NEW_PROPERTY_KEY = PROPERTY_KEY + "_" + list.RootFolder.Name;
            list.ParentWeb.Properties[NEW_PROPERTY_KEY] = TinyXmlSerializer.Serialize(settings);
            list.RootFolder.Properties[PROPERTY_KEY] = TinyXmlSerializer.Serialize(settings);

Sep 10, 2009 at 3:14 PM


I made a similar change to a customized version of the code for a client some time ago, and that works quite well :-) I'll include that in the next released revision here.