SharePoint 2013 中使用代码取特定用户的social tag

本文介绍如何通过编程方式从SharePoint2013中获取指定用户的SocialTag,包括设置环境、引用DLL文件及具体实现代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文讲述如何使用SharePoint 2013 中使用代码取特定用户的social tag。

1. 首先确保Social feature 配置正确,可以打tag,笔者打了三个tag


2. 新建一个Console application,将其target platform 改成X64

3. 引用如下Dll 

Microsoft.Office.Server.UserProfiles.dll

 Microsoft.SharePoint.dll

Microsoft.SharePoint.Taxonomy.dll 

 Microsoft.Office.Server.dll 


3. Program.cs代码 :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint;
using Microsoft.Office.Server.SocialData;
using Microsoft.SharePoint.Utilities;
using Microsoft.Office.Server.UserProfiles;

namespace GetTags
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Please use: GetTags SiteUrl");
            }
            else
            {
                using (SPSite site = new SPSite(args[0]))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        // 取 SocialTagManager
                        SPServiceContext serviceContext = SPServiceContext.GetContext(site);
                        SocialTagManager stm = new SocialTagManager(serviceContext);

                        Console.WriteLine("Get profile manager");
                        UserProfileManager profileManager = new UserProfileManager(serviceContext);                       

                        // 如果在web part中 userloginName可以传 SPContext.Current.Web.CurrentUser.LoginName
                        // 在Console application中使用用户的alias,不带域名
                        Console.WriteLine("Get user profile");
                        UserProfile profile = profileManager.GetUserProfile("userloginName");                        
                        Uri uri = new Uri(web.Url);
                        Console.WriteLine("Start request");

                        // 取对应的用户的social tags
                        var itemTags = stm.GetTags(profile);
                        
                        // 打印  soical tags
                        Console.WriteLine("----------------------------------------------");
                        Console.WriteLine("Tags count: " + itemTags.Length);                         
                        foreach (var tag in itemTags)
                            {                              
                               Console.WriteLine(string.Format("Title: {0} - URL: {1}, Term: {2}", 
                                   tag.Title, 
                                   tag.Url, 
                                   tag.Term.GetDefaultLabel(1033)));                               
                            }
                       
                        // 可以使用 itemTags[0].Delete(); 删除tag
                        // 可以使用 itemTags[0].Update(); 更新tag
                    }
                }
            }

            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }
    }
}

4. 结果为:


5. 可以在 .../my/_layouts/15/thoughts.aspx 中删除tag



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值