Hi, I'm trying to load data from Pages fields from a TreeNode object in the code.
I have a couple of Pages fields on my document type, eight or nine, and is trying to get all the fields through "page.RelatedDocuments". I'm successfully retrieving a couple of the RelatedDocument lists but not all. Is there a better way fetching the related documents from a page?
Code:
foreach (var item in page.RelatedDocuments.DynamicNames) // <-- Only returning some of the lists { RelationshipNameInfo relationshipNameObj = RelationshipNameInfoProvider.GetRelationshipNameInfo(item); var relationShips = page.RelatedDocuments[item]; var relationShipname = relationshipNameObj.RelationshipDisplayName; foreach (var page in relationShips) { if (relationShipName.Contains(stringToMatch)) { var newPage = Helper.GetPageFromGuid(page.NodeGUID.ToString()); var newObject = new NewObject { Name = newPage.GetStringValue("PlayerName", ""), }; listToReturn.Add(player); } } }
What is your Kentico version? Can you use documentHelper?
// Simulates a page GUID. Guid nodeGuid = Guid.NewGuid(); // Retrieves smartphones that are in a specific relationship with a specific page. DocumentQuery smartphones = DocumentHelper.GetDocuments("CMS.Smartphone") .OnSite("CorporateSite") .Path("/Products/", PathTypeEnum.Children) .InRelationWith(nodeGuid, "IsRelatedTo");
Thanks for the reply, Peter,
Yes, I can use DocumentHelper, that query is returning the pages, but not per list, I have no idea what list each page is choosen in.
Or is there something i'm missing here?
Please, sign in to be able to submit a new answer.