Retrieving custom fields for a custom page type

Rita Mikusch asked on July 5, 2017 23:54

Hi,

I have a custom Page Type with some custom fields. And I'm having problems getting the values of those custom fields in my c# code.

Here's my code:

var docs = TreeProvider.SelectNodes().Types("myCustomType").Path("thePath");

StringBuilder s = new StringBuilder();

foreach (var d in docs){

s.AppendLine(d.DocumentName + " " + d.Value("myCustomField"));

}

When I print "s" out, I can see that the DocumentName is retrieved, but not "myCustomField".

According to all the documentation I've read, this SHOULD WORK ... but it isn't :(. Does anybody have any ideas? Thank you.

Correct Answer

Mike Wills answered on July 6, 2017 00:24

Hi Rita,

Try using the overload of SelectNodes that takes the class name as a parameter:

https://devnet.kentico.com/docs/10_0/api/html/M_CMS_DocumentEngine_TreeProvider_SelectNodes_3.htm

And with each TreeNode object, try using the GetValue method.

Mike

0 votesVote for this answer Unmark Correct answer

Recent Answers


Rita Mikusch answered on July 6, 2017 00:32

Awesome, thank you, that worked!

... Kentico drives me a little crazy sometimes!

0 votesVote for this answer Mark as a Correct answer

Mike Wills answered on July 6, 2017 00:34

Good news, I'm glad this helped.

0 votesVote for this answer Mark as a Correct answer

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