tony
-
2/25/2011 5:04:12 AM
dynamic page redirect to first child node under parent node
Just thought someone might find this useful. For example if you need parent node to redirect it to the first child document dynamically, just include the code in Page_load().
string parentNodeAliasPath = (string)CMS.CMSHelper.CMSContext.CurrentPageInfo.NodeAliasPath.ToLower(); parentNodeAliasPath = parentNodeAliasPath.Trim() + "/%";
CMS.TreeEngine.TreeProvider tree = new CMS.TreeEngine.TreeProvider(); DataSet ds = tree.SelectNodes(CMS.CMSHelper.CMSContext.CurrentSiteName, parentNodeAliasPath, CMS.CMSHelper.CMSContext.CurrentDocument.DocumentCulture, false);
if (!CMS.GlobalHelper.DataHelper.DataSourceIsEmpty(ds)) { // If child nodes exist DataView dtView = ds.Tables[0].DefaultView; dtView.Sort = "nodeOrder ASC"; string path = dtView[0]["NodeAliasPath"].ToString(); string resolvedURL = ResolveUrl(CMSContext.GetUrl(path)); Response.Redirect(resolvedURL); } else { //If child nodes do not exist do not redirect }
|