Select document(s)

Select single node by NodeID

 

[C#]

 

using CMS.SiteProvider;

 

// Tree node

CMS.TreeEngine.TreeNode node = null;

// Tree provider

UserInfo ui = UserInfoProvider.GetUserInfo("administrator");

CMS.TreeEngine.TreeProvider tree = new CMS.TreeEngine.TreeProvider(ui);

            

// Get Single node specified by it`s ID

node = tree.SelectSingleNode(nodeId);

 

// Get node name

string result = "The node name is: " + node.NodeName;

 

 

Reading document properties

 

Once you retrieve the TreeNode instance representing a document, you can use the GetValue method to retrieve the document properties:

 

[C#]

 

// Get NewsTitle value of the News document

string newsTitle = (string) node.GetValue("NewsTitle");

 

 

Reading/setting editable region content

 

Once you retrieve the TreeNode instance representing a document, you can use the DocumentContent property to retrieve or set the document properties:

 

[C#]

 

// Get mainText region content of the node representing a page

string mainText = (string) node.DocumentContent["mainText"];

 

// Set mainText region content of the node representing a page (for portal engine pages)

node.DocumentContent.EditableWebParts["mainText"] = "my text";

 

// Set mainText region content of the node representing a page (for ASPX page templates)

node.DocumentContent.EditableRegions["mainText"] = "my text";

 

Please note: if you need to retrieve these values for the currently displayed page, you can use the CMSContext.CurrentPageInfo.EditableItems property.

 

 

Select single node by AliasPath

 

[C#]

 

using CMS.SiteProvider;

 

// Tree node

CMS.TreeEngine.TreeNode node = null;

// Tree provider

UserInfo ui = UserInfoProvider.GetUserInfo("administrator");

CMS.TreeEngine.TreeProvider tree = new CMS.TreeEngine.TreeProvider(ui);

 

// Get Single node specified by it`s site name, aliaspath And culture code

node = tree.SelectSingleNode("CorporateSite""/Products/Notebooks/FS-V2030""en-us");

 

string result = "The node name is: " + node.NodeName;

 

 

Select single document by DocumentID

 

Please note: the difference between DocumentID and NodeID is that DocumentID is specific for particular language version of the document.

 

[C#]

 

using CMS.SiteProvider;

 

// Tree node

CMS.TreeEngine.TreeNode node = null;

// Tree provider

UserInfo ui = UserInfoProvider.GetUserInfo("administrator");

CMS.TreeEngine.TreeProvider tree = new CMS.TreeEngine.TreeProvider(ui);

 

// Get Single document node specified by it`s ID

node = tree.SelectSingleDocument(documentId);

 

string result = "The name of the document (node) is: " + node.DocumentName;

 

 

Select multiple documents

 

[C#]

 

using CMS.SiteProvider;

 

DataSet ds = null;

 

// create a TreeProvider instance

UserInfo ui = UserInfoProvider.GetUserInfo("administrator");

CMS.TreeEngine.TreeProvider tree = new CMS.TreeEngine.TreeProvider(ui);

 

// get dataset of tree nodes specified by alias path and class names (separated by semicolon),

// the second parameter says whether to return default culture documents if the required

// document language version is not available

ds = tree.SelectNodes("CorporateSite","/Products/%", "en-us", True, "cms.menuitem;cms.products");

 

// do something with dataset ...