博客地址:http://blog.csdn.net/FoxDave

上一篇讲了如何获取用户配置文件的相关属性,它属于SharePoint 2013社交功能的一个小的构成部分。社交功能是SharePoint 2013改进的一大亮点。可以在现有网站上开启社交功能或者新建一个专门用于社交用途的社区网站,社交功能包括关注(人或内容)、艾特@、#等功能、有清晰的用户积分制度等等。由于工作中不会有太多关于这方面的开发需求,并且个人觉得这部分做得挺不错,基本的需求应该是够用了(强大的或许就不在SharePoint上了),所以本篇只会用两个小例子展示一下如何用客户端对象模型与SharePoint社交功能进行交互来说明SharePoint 2013社交功能的开发,当然不仅限于客户端对象模型,JSOM和REST也可以做类似的事情。

包括之前提到的用户配置文件相关的开发,在用客户端对象模型做社交相关功能的代码交互开发时,需要引入Microsoft.SharePoint.Client、Microsoft.SharePoint.ClientRuntime和Microsoft.SharePoint.Client.UserProfiles这三个程序集,并在代码文件头部增加如下两个引用:

using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.Social;

首先构建上下文对象:

ClientContext clientContext = new ClientContext("<你的网站URL>");

在Microsoft.SharePoint.Client.Social这个命名空间下,有SocialFeedManager、SocialFeedOptions、SocialPostCreationData和SocialFollowingManager等对象模型可供我们使用,分别跟订阅、回帖、关注等有关。

获取指定用户的动态:

SocialFeedManager feedManager = new SocialFeedManager(clientContext);
SocialFeedOptions feedOptions = new SocialFeedOptions();
feedOptions.MaxThreadCount = 10;
ClientResult<SocialFeed> feed = feedManager.GetFeedFor("<指定的用户>", feedOptions);
clientContext.ExecuteQuery();
for (int i = 0; i < feed.Value.Threads.Length; i++)
{
SocialThread thread = feed.Value.Threads[i];
string postText = thread.RootPost.Text;
Console.WriteLine("\t" + (i + 1) + ". " + postText);
}

获得指定用户关注和被关注的人:

static void Main(string[] args)
{
string serverUrl = "<你的网站URL>";
string targetUser = "<指定的用户>";
ClientContext clientContext = new ClientContext(serverUrl);
SocialFollowingManager followingManager = new SocialFollowingManager(clientContext);
SocialActorInfo actorInfo = new SocialActorInfo();
actorInfo.AccountName = targetUser;
ClientResult<int> followedCount = followingManager.GetFollowedCount(SocialActorTypes.Users);
ClientResult<SocialActor[]> followedResult = followingManager.GetFollowed(SocialActorTypes.Users);
ClientResult<SocialActor[]> followersResult = followingManager.GetFollowers();
clientContext.ExecuteQuery();
Console.WriteLine("当前用户关注的人数: ({0})", followedCount.Value);
IterateThroughPeople(followedResult.Value);
Console.WriteLine("\n谁关注此用户:");
IterateThroughPeople(followersResult.Value);
Console.ReadKey();
} static void IterateThroughPeople(SocialActor[] actors)
{
foreach (SocialActor actor in actors)
{
Console.WriteLine(" - {0}", actor.Name);
Console.WriteLine("\t链接: {0}", actor.PersonalSiteUri);
Console.WriteLine("\t头像: {0}", actor.ImageUri);
}
}

更多内容请参考微软MSDN文档,写得还是很详细清晰的,如果我们在工作中遇到了相关内容的任务,能够提供很有力的参考和帮助。

最新文章

  1. SSIS变量属性中EvaluateAsExpression设置的作用
  2. HTML5探索一(那些新增的标签和属性)
  3. Typecho 代码阅读笔记(一) - 页面渲染及路由机制
  4. SharePoint代码段设计
  5. C语言根据函数名调用对应的函数
  6. poj 2434;bzoj 1686 [Usaco2005 Open]Waves 波纹
  7. OpenCV实现图像上添加汉字 转
  8. linux下64位汇编的系统调用(5)
  9. 如何用ABP框架快速完成项目(面向项目交付编程面向客户编程篇)(1) - 目录
  10. oracle 12g,断电,数据库启动不了,无法登录 并且 报ora-00119和ora-00132错误
  11. WCF之endpoint的binding属性
  12. Centosphp安装cassandra扩展
  13. 甲方安全建设之office365邮箱弱口令检测
  14. windows下更改Mac地址
  15. QT 13 窗口屏幕设置大小与居中显示
  16. iconfont项目成员添加不进去的问题
  17. 大神你好,可以帮我P张图吗?
  18. Write Markdown Syntax Online Document with Sphinx and Pandoc
  19. 【LeetCode-面试算法经典-Java实现】【059-Spiral Matrix II(螺旋矩阵II)】
  20. 如何高效使用Google

热门文章

  1. HTML 5 的data-* 自定义属性
  2. 《Unix网络编程》卷一(简介TCP/IP、基础套接字编程)
  3. LINK : fatal error LNK1104: 无法打开文件“LIBCD.lib”
  4. MySQL 常用命令
  5. js数组的一些操作
  6. [渣译文] 使用 MVC 5 的 EF6 Code First 入门 系列:为ASP.NET MVC应用程序实现继承
  7. gdb调试正执行的程序
  8. 让IE7 IE8支持CSS3 background-size属性
  9. Android 签名工具 shell脚本
  10. hdu3228Island Explorer