SharePoint 2013 中使用代码取特定用户的social tag
2013-11-07 19:34
387 查看
本文讲述如何使用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代码 :
4. 结果为:
5. 可以在 .../my/_layouts/15/thoughts.aspx 中删除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
相关文章推荐
- Sharepoint应用EWSManagedAPI操作Exchange邮箱
- sharepoint 2013 文档库eventhandle权限控制
- sharepoint 2013 自定义列表eventhandle权限控制
- sharepoint 2013 PowerPivot for SharePoint 2013 刷新数据时报错
- sharepoint 2013 文档库 资源管理器打开报错 在文件资源管理器中打开此位置时遇到问题,将此网站添加到受信任站点列表,然后重试。
- sharepoint 2010 使用自定义列表模版创建列表(1)
- sharepoint 2010 使用自定义列表模版创建列表(2)
- sharepoint 2013 未能加载类型"Microsoft.AnalysisServices.SharePoint.Integration.ReportGalleryView"
- sharepoint 2013 列表和库标签 元数据导航配置(1)
- sharepoint 2013 列表和库标签 元数据导航配置(2)
- sharepoint 2013 根据网站模版创建网站,并赋值网站权限 create a site by custom site template
- SharePoint 2013 设置外网(Internet)爬网源
- SharePoint 2013 Search result refinement 如何显示count
- SharePoint 2013 配置 查询拼写纠错(Query Spelling Correction)
- SharePoint 2013 设置搜索导航(Search Navigation)
- SharePoint 2013 配置 查询规则(Query Rule)
- SharePoint 2013 客户端模型(Client Object Model) 调用搜索(Query Search)
- SharePoint 2013 Search KQL 介绍及实例分析
- SharePoint 2013 客户化(Customize) 搜索结果(Search result)-显示模版(Dispaly template)&搜索结果类型(Search Result Type)
- Jquery(Ajax) 调用 SharePoint 2013 Search Rest API 并使用Josn反回结果并简单显示