How to get Page type fields values from code behind.

Manmath Kulkarni asked on February 23, 2017 09:15

Hi,

I am trying to get collection of leaf nodes from tree node collection.
I have defined some fields in Page type form. I am trying to retrieve these field values using ValidationHelper.GetString.

For current document I am able to get value using this

TreeNode doc = DocumentContext.CurrentDocument;
string temp = ValidationHelper.GetString(doc.GetValue("DisplayAt"), "", "");

But for other leaf node I am not able to get field values. It returns empty string.

TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser); TreeNode rootPage = tree.SelectNodes().Path("/").OnCurrentSite().FirstObject;

    TreeNodeCollection collection = rootPage.AllChildren.WithAllData;
    foreach (var v in collection)
    {
        if (v.NodeHasChildren && v.IsRoot() == false)
        {
            foreach (var leaf in v.Children)
            {
                TreeNode t = tree.SelectNodes().Path(leaf.NodeAliasPath).OnCurrentSite().FirstObject;
                string someString= ValidationHelper.GetString(leaf.GetValue("Somevalue"), "", "");
                string[] str1 = someString.Split('|');
                foreach (string s in str1 )
                {
                    if (s.Equals(CurrentSite.SiteName))
                    {
                        LeafNodeList.Add("~" + leaf.NodeAliasPath);
                        coll.Add(leaf);
                        if (leaf.DocumentGUID == doc.DocumentGUID)
                            currentIndex = LeafNodeList.IndexOf("~" + leaf.NodeAliasPath);
                    }
                }
            }
        }
    }

Kindly help. Thanks in advance.
Manmath.

Correct Answer

Jan Hermann answered on February 23, 2017 10:38

Page type fields are available only when you specify the class name, e.g.:

tree.SelectNodes("cms.menuitem")

1 votesVote for this answer Unmark Correct answer

   Please, sign in to be able to submit a new answer.