Kentico 8 get Document Type field value

Semen Shekhovtsov asked on February 7, 2016 16:36

Hi, Can anyone please check what I'm doing wrong here. In the custom Document Type, I created a field Field Type: File, Form Control: Upload File. Created a new page based on this Document Type, uploaded a file. Now in the Document Template aspx file, I'm trying to get that field value, but in all cases got NULL. What I'm doing wrong here?

First way:

TreeProvider treeProvider = new TreeProvider(MembershipContext.AuthenticatedUser);
            TreeNode node = treeProvider.SelectSingleNode(SiteContext.CurrentSiteName, null, DocumentContext.CurrentDocument.DocumentCulture, true, "aos.Core;CMS.Root;CMS.MenuItem", string.Format("NodeGuid ='{0}'", DocumentContext.CurrentDocument.NodeGUID), null, -1, true, null);
            var backgroundValue = node.GetValue("HeaderBackground"); //got NULL

Second way

        var macrosValue = CMS.MacroEngine.MacroContext.CurrentResolver.ResolveMacros("{%CurrentDocument.GetValue(\"HeaderBackground\")#%}"); //got NULL

Third way:

        var headerBackground = DocumentContext.CurrentDocument.GetValue("HeaderBackground"); //got NULL

Thanks!

Recent Answers


Brenden Kehren answered on February 8, 2016 06:36

Have you looked into the DocumentQuery API? This should help you get started (and in a simpler way):

// Get all news items and articles from site containing 'Kentico' in name
var documents = DocumentHelper.GetDocuments()
    .Type("CMS.News", q => q.Default())
    .Type("CMS.SimpleArticle", q => q.Default())
    .OnSite("CorporateSite")
    .WhereLike("DocumentName", "%Kentico%");

foreach (var doc in documents)
{
    var fieldValue = doc.GetValue("ColumnName");
}
0 votesVote for this answer Mark as a Correct answer

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