Getting the value of a custom property in a document (page) from C#

Jan Wintermans asked on October 14, 2018 15:49

How do I get the value of a property in a Kentico Page from C#?

I'm using Kentico 11.

Screenshot: https://imgur.com/a/fhxJOCi

This is what I tried, but did not work:

var document = DocumentHelper.GetDocuments()
                .Where(x => x.NodeClassName.Equals(metadataPage.ClassName))
                .FirstOrDefault();

var documentProperties = document.Properties;
var targetSlug = document.GetValue("MetadataUrlSlug");

The targetSlug is null.

The "MetadataUrlSlug" does show up in the document.Properties, but I don't know how to get the value of the property.

Correct Answer

Jan Wintermans answered on October 15, 2018 09:17

It turned out I had to add "WithCoupledColumns()" after "DocumentHelper.GetDocuments()":

var document = DocumentHelper.GetDocuments()
                .WithCoupledColumns()
                .Where(x => x.NodeClassName.Equals(metadataPage.ClassName))
                .FirstOrDefault();

var targetSlug = document.GetValue("MetadataUrlSlug");
0 votesVote for this answer Unmark Correct answer

Recent Answers


Peter Mogilnitski answered on October 14, 2018 16:56 (last edited on October 14, 2018 18:26)

You are doing everything correctly. Make sure that your first document has this MetadataUrlSlug not null.

var doc = DocumentHelper.GetDocuments("CMS.MenuItem").FirstOrDefault();
var val = ValidationHelper.GetString(doc.GetValue("DocumentName"), "");

Although if you are already has metadataPage (Is it type of treenode?) Why can't you metadataPage.GetValue("MetadataUrlSlug")?

0 votesVote for this answer Mark as a Correct answer

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