0

I am trying to Tag a Url with the "I Like It" using code, i.e. using the SocialTagManager class.

SPServiceContext serviceContext = SPServiceContext.GetContext(SPContext.Current.Site);
SocialTagManager socialTagManager = new SocialTagManager(serviceContext);
UserProfileManager userProfileManager = new UserProfileManager(serviceContext);
UserProfile userProfile = userProfileManager.GetUserProfile(CurrentUser);
SocialTerm[] terms = socialTagManager.GetTerms(userProfile);
Term favTerm = (from t in terms
                            where (t.Term.Name.Equals("i like it", StringComparison.InvariantCultureIgnoreCase))
                            select t.Term).First();

socialTagManager.AddTag(new Uri(Url), favTerm, Title);

But for this, the favTerm should be already there in SharePoint. But if a user has not tagged any page with "I Like it" before then the GetTerms() or GetAllTerms() method does not return any Term for I Like it.

How do I create a new Term if the I Like it Term is not already there?

Thanks in advance

4

1 回答 1

-1

不太确定你在找什么。但是您可以按照本文http://msdn.microsoft.com/en-us/library/ff407956.aspx中所示以编程方式创建标签

TaxonomySession taxSession = mySocialTagManager.TaxonomySession;
TermStore termStore = taxSession.DefaultKeywordsTermStore;
myTerm = termStore.KeywordsTermSet.CreateTerm("term", termStore.DefaultLanguage);
termStore.CommitAll();

但是当 Term 已经在 TermStore 中时,我遇到了这种情况,但是这个术语还没有出现在 User Profile 术语数组中。

于 2012-09-18T15:49:02.570 回答