Guest User

Untitled

a guest
Oct 20th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. // Using Kentico site export, find all templates that include DocumentDataSource with path expressions pointing to other documents (which will break when document tree moves)
  2. // Uses LINQPad's C# Statements format
  3.  
  4. //Root directory where the unzipped Kentico export file sit (with Data subdirectory)
  5. string exportDirPath = @"<UNZIPPED_FULL_SITE_EXPORT>\Data";
  6.  
  7. //XML files for documents and templates definitions
  8. XDocument templateSource = XDocument.Load(exportDirPath + @"\Objects\cms_pagetemplate.xml.export");
  9. XDocument siteTemplateSource = XDocument.Load(exportDirPath + @"\Site\cms_pagetemplate.xml.export");
  10.  
  11.  
  12. //combine the template sources with the same shape
  13. var allTemplates =
  14. (
  15. (from t1 in templateSource.XPathSelectElements("//NewDataSet/cms_pagetemplate") select t1)
  16. .Union
  17. (from t2 in siteTemplateSource.XPathSelectElements("//NewDataSet/cms_pagetemplate") select t2)
  18. ).OrderBy(t => t.Element("PageTemplateDisplayName").Value);
  19.  
  20. var matches =
  21. (
  22. from t in allTemplates
  23. where t.Element("PageTemplateWebParts") != null
  24. let webpartsXML = XDocument.Parse(t.Element("PageTemplateWebParts").Value) //webparts are encoded XML inside an XML element
  25. let props =
  26. (
  27. from part in webpartsXML.XPathSelectElements("//webpart[@type='DocumentsDataSource']")
  28. let pathCol = part.XPathSelectElements("property[@name='path']") //realistically, can return one or none, in the collection
  29. where pathCol.Count()>0 //not all DataSources have path, no idea what it picks up then, but we don't need to change it
  30. select (new {
  31. ControlID = part.Attribute("controlid").Value,
  32. Path = pathCol.First().Value
  33. })
  34. )
  35. let templateName = t.Element("PageTemplateDisplayName").Value
  36. where props.Count() > 0 //only show templates that actually have DocumentsDataSource webparts
  37. select new {templateName, props}
  38. );
  39.  
  40. matches.Dump("Templates with enumerations of other pages");
Add Comment
Please, Sign In to add comment