Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Set new enterprise keywords

$
0
0

Hi,

I have the following problem: I want to set enterprise keywords in a document library. The program I wrote works fine for already existing enterprise keywords, but not for new ones. 

This is the function which generates a new enterprise keyword :

Public Shared Function ensurekeyword(taxField As TaxonomyField, values As String) As Term

        Dim ctx = taxField.Context
        Dim taxSession As TaxonomySession = TaxonomySession.GetTaxonomySession(ctx)
        Dim termstore As TermStore = taxSession.GetDefaultKeywordsTermStore
        ctx.Load(termstore)
        Dim keywords As TermCollection = termstore.KeywordsTermSet.GetAllTerms
        Dim term As Term = keywords.GetByName(value)

        Dim result As Term = Nothing
        Try
            ctx.Load(term)
            ctx.ExecuteQuery()
            result = term
        Catch ex As Exception
        End Try
        If result Is Nothing Then
            result = termstore.KeywordsTermSet.CreateTerm(value, 1033, Guid.NewGuid)
            termstore.CommitAll()

            ctx.Load(result)
            ctx.ExecuteQuery()
            Return result
        Else
            Return result
        End If
    End Function

Can somebody tell me how I can generate a new enterprise keyword? I've already looked in the internet and a lot of people were using the "commitAll()" method, but this doesn't work in my program.


Viewing all articles
Browse latest Browse all 7589

Trending Articles