Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Lets say I have a whole lot of Terms in the Term Store.

When I create the Term items I am setting a custom property like this:

Term term = termSet.CreateTerm("ParentTerm", 1029, new Guid("{0368F902-740B-4855-A4A7-FA8F96813CCB}"));
term.SetCustomProperty("OBJID", "2222"); 
termStore.CommitAll();

So far so good, but now how would I perform a search to find this particular term based on its custom property, in this case OBJID.

Is there built in search methods for terms?

There is the

TaxonomySession session = new TaxonomySession(site);
session.GetTerm("GUID_OF_TERM");

But this is not the same as the term custom property - thanks!

share|improve this question

4 Answers 4

Check if this exists:

term.CustomProperties["key"] 

Or if you want to check all of the Term Set:

termSet.Terms.Select(x => x.CustomProperties["key"] != null);

This could be made into a recursive function to check for all child terms.

share|improve this answer

There is no out of the box functionality to search for this. You have to build some kind of recursive function to do this on your own - ultimatley you need to traverse all Terms, which likely would kill performance.

I would suggest you rethink your design.

share|improve this answer

Try modifying the below code. I use it to recursively find the first Tag that matches a Term label. You would have to change the if statement to query for your custom property.

private Term GetChildTermThatMatchesName(Term sourceTerm, string name)
{

   Term  term = null;

   if (sourceTerm != null)
   {
      if (sourceTerm.TermsCount > 0)
      {
         if (sourceTerm.Terms.Any(t => t.Name == TaxonomyItem.NormalizeName(name)))
         {
            term =  sourceTerm.Terms.First(t => t.Name == TaxonomyItem.NormalizeName(name));
         }
         else
         {
            /* Recusively loop through child until we find our first match */
            foreach (Term childTerm in sourceTerm.Terms)
            {
               if (term == null)
               {
                  term = GetChildTermThatMatchesName(childTerm, name);
               }
               else
               {
                  break;
               }
            }
         }
      }
   }


   return term;
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.