开发者

Social tags not seen in My Site after I add it using the API

Here is my code to tag a page with a tag and title. Later on in the code, I loop through and display the URL and the associated tag. Here I see my tag, but I do not see it in "My site - Tags and Notes".

protected override void CreateChildControls()
{
    Control control = Page.LoadControl(_ascxPath);
    Controls.Ad开发者_运维技巧d(control);

    Literal lt = new Literal();

    SPServiceContext objServiceContext = SPServiceContext.Current;
    SocialTagManager objSocialTagManager = new SocialTagManager(objServiceContext);

    try
    {
        TermStore objTermStore = objSocialTagManager.TaxonomySession.DefaultKeywordsTermStore;
        Term objTerm = objTermStore.KeywordsTermSet.CreateTerm("I Like Iting", objTermStore.DefaultLanguage);

        System.Uri objURI = new Uri("http://spdev01/Lists/Calendar/calendar.aspx");

        SocialTag objTag = objSocialTagManager.AddTag(objURI, objTerm, "Calendar YoYo");

        lt.Text = objTag.Url.ToString() + objTag.Term.Name + "<br/><br/>";
    }
    catch (Exception ex)
    {
        lt.Text = ex.Message + ex.StackTrace + "<br/>";
    }
    finally
    {
        Controls.Add(lt);
    }

    //Display all the tags
    string myaccount = @"domain\sharepoint";
    UserProfileManager objUPManager = new UserProfileManager(objServiceContext);
    UserProfile objProfile = objUPManager.GetUserProfile(myaccount);
    SocialTag[] allTags = objSocialTagManager.GetTags(objProfile);

    Literal ltTags = new Literal();

    foreach (SocialTag tag in allTags)
        ltTags.Text += string.Format("Tag: {0} - URL: {1}<br/>", tag.Term.Name, tag.Url.ToString());

    Controls.Add(ltTags);
}

I don't see the custom tag in "My Site" but I see it when I loop through the "MyTags" property. Do I have to run a specific job to see it under "My site"?


After creating a new term object, commit the changes on TermStore object objTermStore.CommitAll();

And after creating the SocialTag update the new object objTag.Update();

Once these methods are called, you will be able to see the Tag in "My Site"

Regards,

Ram.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜