0

i want to check if Term is available in termSet programatically by term name or label. if it not available then i want to create it, How i check? I am using this code but does not work, what will be the correct code?

if (termSet.GetTerms("MyTerm",false) == null)
                {
                    termSet.CreateTerm("MyTerm", 1033);
                    termStore.CommitAll();
                }
2

GetTerms returns a TermCollection object, which, even if it's empty, will not be null. You probably want to do something like:

TermCollection results = termSet.GetTerms("MyTerm", false);
if (results.Count == 0)
{
    termSet.CreateTerm("MyTerm", 1033);
    termStore.CommitAll();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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