Solution to SharePoint 2013 Issue: Content Search Web Part Does Not Retain Properties When Creating a Site From a Custom Template

The Scenario

Our goal was to have a reusable site template that could be used to provision a SharePoint site with pre-existing web parts via a workflow. We started by creating a team site, adding various web parts, libraries and custom metadata. We finished by creating a home page with a Content Search web part that would show the ten most recent documents across all libraries in the current site. We then saved this site as a template.

Next, we instructed the workflow to create a new subsite using this template whenever an item was added to a list at the root site. But after populating documents on the subsite, we found that our web part was not showing document images properly. The issue can be seen in the image below.

SharePoint 2013 - Content Search Web Part Does Not Retain Properties When Creating a Site From a Custom Template

Problem & Analysis

The SharePoint Content Search web part does not retain all of its properties when a site is provisioned from a custom template in SharePoint Server 2013. We noticed that after templatizing the site and then using the template to create a new site, the Content Search web part did not have the expected properties.

When we compared the web part settings from a newly provisioned site to the web part properties on the original template site, we found that the Item dropdown list was set to a different value. After multiple attempts of recreating sites and making modifications to the template, we decided that it was time to crack open the site template itself. By using Visual Studio, you can open the site template and make modifications.

But, there is a quicker and easier solution.

SharePoint 2013 - Content Search Web Part Does Not Retain Properties When Creating a Site From a Custom Template 2

Solution

1. Download the wsp file and rename it to .cab

SharePoint 2013 - Content Search Web Part Does Not Retain Properties When Creating a Site From a Custom Template 3

After renaming it, it should look like this:

SharePoint 2013 - Content Search Web Part Does Not Retain Properties When Creating a Site From a Custom Template 4

2. Extract the .cab file to C: using WinRar or any other unzip utility

SharePoint 2013 - Content Search Web Part Does Not Retain Properties When Creating a Site From a Custom Template 5

After extracting the file, you’ll have access to the following folders:

SharePoint 2013 - Content Search Web Part Does Not Retain Properties When Creating a Site From a Custom Template 6

3. Open C:JobSiteTemplateJobSiteTemplateModulesElements.xml

4. Search for the content search web part, then look for the ItemTemplateId property

SharePoint 2013 - Content Search Web Part Does Not Retain Properties When Creating a Site From a Custom Template 7

5. Replace the tilde (~) with the XML encoded entity ~ and save the file. After the change it should look like this:

SharePoint 2013 - Content Search Web Part Does Not Retain Properties When Creating a Site From a Custom Template 8

6. Recreate the .cab file by using this two-step process:

First you need to create a DDF file. I used ddfgenerator from codeplex. Download it and run a command to generate the DDF file.

SharePoint 2013 - Content Search Web Part Does Not Retain Properties When Creating a Site From a Custom Template 9

Then you will have to run the makecab utility to create the .cab file.

SharePoint 2013 - Content Search Web Part Does Not Retain Properties When Creating a Site From a Custom Template 10

7. Rename .cab to .wsp and upload it to the solution gallery of the SharePoint site collection.

That’s it! Your Content Search web part should now retain its properties when creating SharePoint sites from a custom template.

Conclusion

It’s apparent that there is a bug in templating a site that uses a Content Search Web Part. Until Microsoft patches this, we will have to go with this manual workaround. Give it a try, share your results, and let us know if you find a better solution!

Feel free to reach out should you have questions or need help with Microsoft SharePoint.

Written by:
Abdur Raheem, Senior SharePoint Consultant, FMT Consultants

Posted by: 

©
2023
 FMT Consultants
|
Privacy Policy
X
FMT

Contact Us

X
FMT

Newsletter Sign-up

menu linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram