Get/set value of "Multiple category selector" form control field.

Targutai Yesugei asked on August 14, 2017 08:43


I need to get/set value of field with "Multiple category selector" form control field.

I'm getting treenode by following code:

 var treeNode = DocumentHelper.GetDocuments("classname")
            .WhereEquals("NodeID", 123)

And it returns perfect tree node - i can work with almost all fields, except wanted one. When i'm trying to get value of this form control type field - it always returns null.

Thanks in advance!

Recent Answers

Trevor Fayas answered on August 14, 2017 14:09

the multiple category selector sets the documents categories, it does not save the category name's in the field.

you can use my advanced category selector on the market place and set the save mode to "field" or "field and categories" since this will save the category name/guid/id to the field, or you can look at the documents categories using the api. I think the treenode object had a categories property you can loop through, otherwise just use either the categoryinfoprovider class

0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on August 14, 2017 20:32 (last edited on August 14, 2017 21:06)

I second Trevor. Multiple categories selector is just a different way of assigning categories. If you go to document properties/categories and assign categories there you will achieve exactly the same. if you have a tree node you can use API to add/remove categories

// Gets the category
CategoryInfo category = CategoryInfoProvider.GetCategoryInfo("Dogs", SiteContext.CurrentSiteName);

if (category != null)
    // Gets a page
   var treeNode = DocumentHelper.GetDocuments("classname")
            .WhereEquals("NodeID", 123)

    // Adds the page to the category
    DocumentCategoryInfoProvider.AddDocumentToCategory(treeNode.DocumentID, category.CategoryID);

P.S. Don't forget that categories get assigned per document (not per node).So if have different cultures on your site like French and English then for a given node you might have 2 documents: English and French. If you assign categories to English they don't get assigned to French.

1 votesVote for this answer Mark as a Correct answer

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