Condividi tramite


SocialTagManager.AddTag Method (Uri, Term)

Creates a SocialTag object with the specified Uri and Term.

Namespace:  Microsoft.Office.Server.SocialData
Assembly:  Microsoft.Office.Server.UserProfiles (in Microsoft.Office.Server.UserProfiles.dll)

Syntax

'Declaration
Public Function AddTag ( _
    url As Uri, _
    term As Term _
) As SocialTag
'Usage
Dim instance As SocialTagManager
Dim url As Uri
Dim term As Term
Dim returnValue As SocialTag

returnValue = instance.AddTag(url, term)
public SocialTag AddTag(
    Uri url,
    Term term
)

Parameters

Return Value

Type: Microsoft.Office.Server.SocialData.SocialTag

Remarks

The social tag is external, and therefore visible to users other than the owner, by default.

Examples

using (SPSite siteColl = new SPSite(url))
{
   SPServiceContext serviceContext = SPServiceContext.Current;
   SocialTagManager mySocialTagManager = new SocialTagManager(serviceContext);
 
   UserProfileManager myProfileManager = new UserProfileManager(serviceContext);
   string myAccount = "mydomain\\myalias";
   UserProfile myProfile = myProfileManager.GetUserProfile(myAccount);
 
   System.Uri uri = new System.Uri("url");

   TaxonomySession taxSession = mySocialTagManager.TaxonomySession;
   TermStore termStore = taxSession.DefaultKeywordsTermStore;
   Term term = termStore.KeywordsTermSet.CreateTerm(keyword, termStore.DefaultLanguage);

   SocialTag newTag = mySocialTagManager.AddTag(uri, term);
 
 
   SocialTag[] myTags = mySocialTagManager.GetTags(myProfile);
 
   foreach (SocialTag aTag in myTags)
   {
      output.Write("<br/> Tag: " + " " + aTag.Url.ToString() + " " + aTag.Term.Name.ToString());
   }
 
}
Using siteColl As New SPSite(url)
   Dim serviceContext As SPServiceContext = SPServiceContext.Current
   Dim mySocialTagManager As New SocialTagManager(serviceContext)

   Dim myProfileManager As New UserProfileManager(serviceContext)
   Dim myAccount As String = "mydomain\myalias"
   Dim myProfile As UserProfile = myProfileManager.GetUserProfile(myAccount)

   Dim uri As New System.Uri("url")

   Dim taxSession As TaxonomySession = mySocialTagManager.TaxonomySession
   Dim termStore As TermStore = taxSession.DefaultKeywordsTermStore
   Dim term As Term = termStore.KeywordsTermSet.CreateTerm(keyword, termStore.DefaultLanguage)

   Dim newTag As SocialTag = mySocialTagManager.AddTag(uri, term)


   Dim myTags() As SocialTag = mySocialTagManager.GetTags(myProfile)

   For Each aTag As SocialTag In myTags
       output.Write("<br/> Tag: " & " " & aTag.Url.ToString() & " " & aTag.Term.Name.ToString())
   Next aTag

End Using

See Also

Reference

SocialTagManager Class

SocialTagManager Members

AddTag Overload

Microsoft.Office.Server.SocialData Namespace