Skip to content

Instantly share code, notes, and snippets.

@arafalov
Created June 14, 2012 14:45
Show Gist options
  • Save arafalov/2930773 to your computer and use it in GitHub Desktop.
Save arafalov/2930773 to your computer and use it in GitHub Desktop.
Using Kentico site export, find all templates that include DocumentDataSource with path expressions pointing to other documents (which will break when document tree moves)
// Using Kentico site export, find all templates that include DocumentDataSource with path expressions pointing to other documents (which will break when document tree moves)
// Uses LINQPad's C# Statements format
//Root directory where the unzipped Kentico export file sit (with Data subdirectory)
string exportDirPath = @"<UNZIPPED_FULL_SITE_EXPORT>\Data";
//XML files for documents and templates definitions
XDocument templateSource = XDocument.Load(exportDirPath + @"\Objects\cms_pagetemplate.xml.export");
XDocument siteTemplateSource = XDocument.Load(exportDirPath + @"\Site\cms_pagetemplate.xml.export");
//combine the template sources with the same shape
var allTemplates =
(
(from t1 in templateSource.XPathSelectElements("//NewDataSet/cms_pagetemplate") select t1)
.Union
(from t2 in siteTemplateSource.XPathSelectElements("//NewDataSet/cms_pagetemplate") select t2)
).OrderBy(t => t.Element("PageTemplateDisplayName").Value);
var matches =
(
from t in allTemplates
where t.Element("PageTemplateWebParts") != null
let webpartsXML = XDocument.Parse(t.Element("PageTemplateWebParts").Value) //webparts are encoded XML inside an XML element
let props =
(
from part in webpartsXML.XPathSelectElements("//webpart[@type='DocumentsDataSource']")
let pathCol = part.XPathSelectElements("property[@name='path']") //realistically, can return one or none, in the collection
where pathCol.Count()>0 //not all DataSources have path, no idea what it picks up then, but we don't need to change it
select (new {
ControlID = part.Attribute("controlid").Value,
Path = pathCol.First().Value
})
)
let templateName = t.Element("PageTemplateDisplayName").Value
where props.Count() > 0 //only show templates that actually have DocumentsDataSource webparts
select new {templateName, props}
);
matches.Dump("Templates with enumerations of other pages");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment