Sunday 1 November 2015

SharePoint: How to troubleshoot issues with Save as template

On an upgrade project to SharePoint 2013 we ran into an issue where a specific site couldn’t be saved as a template (with or without content). You get the non-descriptive “Sorry, something went wrong” and “An unexpected error has occurred” messages. Funny enough the logged Correlation Id is totally absent from the ULS logs, so no help there.
What you can do next is turn on advanced debugging mode by configuring the following entries in the web.config of the SharePoint site:
  • Turn on the call stack (CallStack="true")
  • Disable custom errors in Visual Studio (<customErrors mode="Off" />)
  • Enable compilation debugging (<compilation debug="true">)
If you then retry your action you’ll find additional information in the Event Log or on the page.
Exception information: 
    Exception type: InvalidOperationException 
    Exception message: Error generating solution files in temporary directory. 
   at Microsoft.SharePoint.SPSolutionExporter.ExportWebAsSolution() 
   at Microsoft.SharePoint.SPSolutionExporter.ExportWebToGallery(SPWeb web, String solutionFileName, String title, String description, ExportMode exportMode, Boolean includeContent, String workflowTemplateName, String destinationListUrl, Action`1 solutionPostProcessor, Boolean activateSolution) 
   at Microsoft.SharePoint.ApplicationPages.SaveAsTemplatePage.BtnSaveAsTemplate_Click(Object sender, EventArgs e) 
   at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) 
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
What this means is that the export operation ran into an issue. We can find the partial export in the temporary directory
Temporary Export Location
If you investigate the contents of the “SPSolutionExporter” folder, you’ll eventually find the issue. In our case the XML generation aborted on the Expiration Policy of one of the Content Types.
image 
So while your issue might be different, this method should provide you with more insight on the issue and take appropriate action.

Addendum

The Content Type/Policy issue in our setup was caused due to a corrupt XmlDocument that describes the changes made to Information Policies. By removing this invalid XmlDocument we were able to save the site as template:
using (SPSite site = new SPSite(url))
{
    using (SPWeb web = site.OpenWeb())
    {
        foreach (SPContentType ct in web.ContentTypes)
        {
            ct.SchemaXmlWithResourceTokens = Regex.Replace(ct.SchemaXmlWithResourceTokens, @"<XmlDocument NamespaceURI=""microsoft.office.server.policy.changes"">.+?</XmlDocument>", "");
            ct.Update();
        }
    }
} 

0 comments:

Post a Comment