Quantcast
Channel: SharePoint 2010 - General Discussions and Questions forum
Viewing all articles
Browse latest Browse all 17574

Setting enterprise keywords locally works perfectly, but using a WCF service exposing this functionality fails.

$
0
0

Update:

I've overcome all the issues when it comes to updating the taxonomy stores and enterprise keywords from a LOCAL console app.

However, impersonating as the same user, using the same code, through a deployed WCF service does not work at all.

It updates the termstores, but it CLEARS the enterprise keyword's column.

Updating all other MMD fields works fine.

This is really frustrating and I really want to know what tiny little probably insiginifcant/arcane/esoteric/counter-intuitive aspect of sharepoint/sharepoint api is causing this to fail.

Thank you so much in advance.

Original Post:

I'm attempting to set the enterprise keywords field of a document library and it's not working.

I've been at this for days trying to find out what I was missing, which is obviously very frustrating.

All other managed metadata fields can be set, so thats not the issue.

No error is thrown.

On LISTS the following code works like a charm, but even with a newly created document library the enterprise keywords will not update. Please help !

The code I've been using to try to figure out this problem is as follows, it works on lists but not libraries:

            SPSite sp = new SPSite("http://myserver");

            var web = sp.OpenWeb();

            var tax = new TaxonomySession(sp);

             // my document list

            var list = web.Lists["myfrickingdocuments"];

            // hidden list to get wssid's

            var hidden = web.Lists["TaxonomyHiddenList"];

            //enterprise keywords field    
            var field1 = list.Fields.GetFieldByInternalName("TaxKeyword") as TaxonomyField;
            var field2 = list.Fields.GetFieldByInternalName("TaxKeywordTaxHTField");

             // grabs the already populated keywords termset (previous code added all the taxonomy terms)

            // then grabs the first term.

            var atermset = tax.TermStores[0].GetTermSet(field1.TermSetId);
            var aterm = atermset.Terms[0];
            // grab the existing term from the taxonomy hiddenlist
            var firstterm =

                       hidden.Items.Cast<SPListItem>().

                       Where(o =>o["IdForTerm"].ToString().Equals(aterm.Id.ToString())).FirstOrDefault();


            //  loop through all the items in the list and set the same enterprise keywords values

           //  just to test the concept

            for (int x = 0; x < list.Items.Count; x++)
            {

                var item = list.Items[x];
            

                // get the term label in english

                string termlabel = aterm.GetDefaultLabel(1033);
              
                // create the taxonomy field value
                 var termfield = new TaxonomyFieldValue(firstterm["ID"].ToString()+ ";#" + aterm.Name,field1);

                // set the enterprise keyword fields
                item[field1.Id] = termfield;
                item[field2.Id] = aterm.Name + "|" + aterm.Id.ToString();
                // update the data in sp
                item.SystemUpdate();
            }



Viewing all articles
Browse latest Browse all 17574

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>