Sitefinity CMS

Moving Pages in SiteMap Send comments on this topic.
See Also
Developing with Sitefinity > Pages > Pages API Walkthrough > Pages > Moving Pages in SiteMap

Glossary Item Box

This section demonstrates various ways in which you can move pages in the SiteMap. Pages can change parents or be reordered inside of a parent.

Change the parent of a page:

SetParent Copy Code
// create a new instance of CmsManager
Telerik.Cms.CmsManager cmsManager = new Telerik.Cms.CmsManager();
// get the SiteMap node of the page to be moved
Telerik.Cms.Web.CmsSiteMapNode childNode = (Telerik.Cms.Web.CmsSiteMapNode)SiteMap.Provider.FindSiteMapNode("~/Test1/News/Child1.aspx");
// get the SiteMap node of the new parent
Telerik.Cms.Web.CmsSiteMapNode newParentNode = (Telerik.Cms.Web.CmsSiteMapNode)SiteMap.Provider.FindSiteMapNode("~/Test1/ChangedName.aspx");
// let's move the page represented by childNode to be the child of the page represented by the newParentNode
cmsManager.SetParent(childNode.CmsPage.ID, newParentNode.CmsPage.ID);

 

Change page’s parent and specify its position among the new sibling pages:

SetParent Copy Code
// create a new instance of CmsManager
Telerik.Cms.CmsManager cmsManager = new Telerik.Cms.CmsManager();
// get the SiteMap node of the page to be moved
Telerik.Cms.Web.CmsSiteMapNode childNode = (Telerik.Cms.Web.CmsSiteMapNode)SiteMap.Provider.FindSiteMapNode("~/Test1/News/Child1.aspx");
// get the SiteMap node of the new parent
Telerik.Cms.Web.CmsSiteMapNode newParentNode = (Telerik.Cms.Web.CmsSiteMapNode)SiteMap.Provider.FindSiteMapNode("~/Test1/ChangedName.aspx");
// let's move the page represented by childNode to be the child of the page represented by the newParentNode
// notice the last arugment "0". By setting the ordinal to 0, we have explicitely decided that the childPage should be a
// first childPage in the new parent
cmsManager.SetParent(childNode.CmsPage.ID, newParentNode.CmsPage.ID, 0);

Note that both of the above SetParent methods can be called by passing the actual ICmsPage objects instead of their IDs.

Change page order inside of a parent page:

SetPageOrdinal Copy Code
// create a new instance of CmsManager
Telerik.Cms.CmsManager cmsManager = new Telerik.Cms.CmsManager();
// get the SiteMap node of the page to be moved
Telerik.Cms.Web.CmsSiteMapNode childNode = (Telerik.Cms.Web.CmsSiteMapNode)SiteMap.Provider.FindSiteMapNode("~/Test1/ChangedName/Child1.aspx");
// the childNode page is a first child of its parent. Let's make it the second child.
// NOTE that page ordinals are zero based, meaning that the first child has the ordinal
// of value 0
cmsManager.SetPageOrdinal(childNode.CmsPage.ID, 1);
Note that you can page an actual CmsPage object to SetPageOrdinal method instead of the ID of the page.

See Also