0

I have a sharepoint 2010 environment with some custom solutions. Now I try to understand this piece of custom code. Can someone tell me whats happening. I would like to change this code, it needs to remove the terms only if the current terms are not empty. The reason why I would this is, sometimes these terms are filled, but sometimes they are empty after. I don't want to remove the terms if there is no new term for in place.

// check if these terms are equal
            var termComparer = new TermComparer();

            // original terms
            var removedTerms = originalTerms.Except(actualTerms, termComparer);

            // current terms
            var addedTerms = actualTerms.Except(originalTerms, termComparer);

            // Remove deleted terms
            foreach (var term in removedTerms)
            {
                DiagnosticsService.LogMessage("Removing term " + term.Labels.First().Value, 0, DiagnosticsCategory.Jobs);

                profile[profileFieldName].RemoveTaxonomyTerm(term);
            }

            // check object value 
            if (addedTerms != null)
            {
                // Remove added terms
                foreach (var term in addedTerms)
                {
                    if (term != null)
                    {
                        profile[profileFieldName].AddTaxonomyTerm(term);
                    }
                }
            }

            profile.Commit();
0

Something like this?

// Remove deleted terms if addedTerms is not null and has at least on item in the collection

if(addedTerms != null && addedTerms.Count > 0){ // addedTerms.Count may be incorrect property based on that I have no knowledge of the type of addedTerms...
    // Remove original terms
    foreach (var term in removedTerms)
    {
        DiagnosticsService.LogMessage("Removing term " + term.Labels.First().Value, 0, DiagnosticsCategory.Jobs);

         profile[profileFieldName].RemoveTaxonomyTerm(term);
    }

    // Add current terms
    foreach (var term in addedTerms)
    {
          if (term != null)
          {
              profile[profileFieldName].AddTaxonomyTerm(term);
          }
    }
}

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.