問題 add/update a value to the enterprise keyword column programatically

  • יום שלישי 01 מאי 2012 08:39
     
     

    Hi, I am not able to find a resource/article which deals with adding a tag grammatically to the enterprise keywords column of a list item in shared docs. An example would be great.

כל התגובות

  • יום שלישי 01 מאי 2012 09:02
     
     

    Look my blog post (localized!).

    There are some examples.


    Don't happy, be worry...



    • נערך על-ידי Aviw_ יום שלישי 01 מאי 2012 09:03
    •  
  • יום שלישי 01 מאי 2012 09:07
     
     
    I went through your post, i think it deals with social tags. I am trying out with enterprise keywords tagging programatically..Or did i read your blog wrong?
  • יום שלישי 01 מאי 2012 11:37
     
     

    The following code, only adds the tags to the TermStore but not to the Enterprise keywords  column of the list.

      SPList list = web.Lists["Shared Documents"];
     SPListItem item = list.GetItemById(2);// Id of the document
      string keywordString = "tag1,tag2"; //comma seperated tags

     TaxonomyField managedField = list.Fields.GetFieldByInternalName("TaxKeyword") as TaxonomyField;

                            if (managedField != null)
                            {
                                TaxonomySession session = new TaxonomySession(item.Web.Site, false);
                                TermStore termStore = session.TermStores[managedField.SspId];
                                TermSet termSet = termStore.GetTermSet(managedField.TermSetId);

                                string[] keywords = keywordString.Split(',').Select(s => s.Trim()).ToArray();

                                var terms = new List<Term>();

                                foreach (string keyword in keywords)
                                {
                                    Term keywordTerm;
                                    if (!termSet.Terms.Any(t => t.Name == TaxonomyItem.NormalizeName(keyword)))
                                    {
                                        keywordTerm = termSet.CreateTerm(keyword, CultureInfo.CurrentCulture.LCID);
                                        termStore.CommitAll();
                                    }
                                    else
                                    {
                                        keywordTerm = termSet.Terms[keyword];
                                    }

                                    terms.Add(keywordTerm);
                                }

                                managedField.SetFieldValue(item, terms);

                            }


                        }



    Code referred from:
    http://sharepoint.stackexchange.com/questions/19389/set-multiple-values-to-enterprise-keywords-taxonomyfield

    It does not however add the tags to the Enterprise keywords  column of the list,Any ideas on how to solve it?


  • יום שלישי 01 מאי 2012 13:46
     
     
    Hello, can somebody help me with this.....i am not able to store  it in the Enterprise keywords column so that it can be tagged and searched....
  • יום שלישי 01 מאי 2012 15:24
     
     
    I am not trying to add it to the TermStore. The program is already successfully adding it to System\Keyword. I am trying to add it to the Enterprise Keywords column of the list and I don't know how to do it ...
    • נערך על-ידי sanjuv יום שלישי 01 מאי 2012 15:33 clarification
    •