Question

Is it possible to get an array/list of document properties from a Kentico TreeNode object?

My use case is I would like to write a class that wraps a custom Document Type. This class will have a method that outputs a formatted string that includes values entered by the user in the CMSDesk.

If I know the name of the property in advance I can do the following:

(TreeNode)node.GetValue("Key");

However, because properties could be added or removed from the Document Type in the CMS Site Manager, I don't want to hard code any strings in the class.

Instead, I'd like to access them kind of like this:

string[] keys = (TreeNode)node.GetKeys();
Dictionary<string, string> dictionary = new Dictionary<string, string>();

foreach(string key in keys)
{
  dictionary.Add(key, node.GetValue(key));
}

I don't see a method on the TreeNode object that would give me the data I'm looking for--is there a way to do this?

Was it helpful?

Solution

It might depend on if you are creating a new TreeNode or retrieving it from the Content Tree.

If you are using SelectSingleNode or SelectNodes to populate your node object than node.ColumnNames will give you a list of all the columns/fields that come back with that node's class.

foreach (string column in node.ColumnNames)
{
     //do something helpful with each one
     string value = ValidationHelper.GetString(node.GetValue(column), string.Empty);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top