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

本篇我们应用SharePoint CSOM(.NET)来读取用户配置文件的信息,个人开始逐渐倾向于客户端模型,因为不用远程登录到服务器去开发,在本机就可以玩了。

打开本地的Visual Studio 2015,选择新建项目,我们新建一个Windows Form应用程序吧,好久没用了,命名为WindowsFormsSPUserProfile。

应用CSOM,我们首先要对我们的项目添加客户端的引用。右键点击项目节点, 选择添加引用,在弹出窗体的右上角输入sharepoint进行搜索,选择Client、Client.Runtime、Client.UserProfile这三个dll添加,注意版本要选择15.0.0.0。

然后我们拖一个Label,一个TextBox,一个Button,一个DataGridView到窗体上,作为输入参数,输入网站集的URL,然后用DataGridView显示出所有的用户配置文件。

双击按钮控件,后台将自动生成button_Click事件方法,我们就在此处写我们的逻辑代码部分。

首先对输入框的Site URL部分做一下判定,这里用作演示我们就只判断一下非空条件,实际过程可能会涉及到诸如地址是否合法等问题。

接下来就在else分支中写主要的获取逻辑代码。在这个例子中,我们大致的思路是为:将某个网站集的用户读取出来,进而获取该用户的配置文件的属性集合。首先将用户列表加载到DataGridView中,然后在选择具体的某个用户时显示所选择用户的配置文件的属性集合信息。

首先将用户信息加载到控件上,WinForm好久不用了,所以方法较为笨拙。

然后配置DataGridView控件的Click事件,获取选中的行得到用户名信息,进而获得属性集合信息。

下面附上完整代码,比较粗糙,仅作示例用。

using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.UserProfiles;
using System;
using System.Data;
using System.Text;
using System.Windows.Forms; namespace WindowsFormsSPUserProfile
{
public partial class MainForm : System.Windows.Forms.Form
{
ClientContext mClientContext = null;
public MainForm()
{
InitializeComponent();
} private void buttonOK_Click(object sender, EventArgs e)
{
if (txtSiteURL.Text == "")
{
MessageBox.Show("请输入网站集地址。");
}
else
{
//todo
//获取输入的网站集URL
string siteUrl = txtSiteURL.Text;
//构建上下文对象
if (mClientContext == null)
{
mClientContext = new ClientContext(siteUrl);
}
//获取网站网站集的所有用户
UserCollection users = mClientContext.Web.SiteUsers;
mClientContext.Load(users);
mClientContext.ExecuteQuery();
//构建用户表
DataTable table = new DataTable();
table.Columns.Add("User Name", typeof(string));
foreach (User u in users)
{
DataRow row = table.NewRow();
row[0] = u.LoginName;
table.Rows.Add(row);
}
dataGridView.DataSource = table;
}
} private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
//窗体关闭前释放资源
if (mClientContext != null)
{
mClientContext.Dispose();
}
} private void dataGridView_MouseClick(object sender, MouseEventArgs e)
{
//获取双击行的用户
string userName = dataGridView.SelectedRows[0].Cells[0].Value.ToString();
//获取人员管理器
PeopleManager peopleManager = new PeopleManager(mClientContext);
//获取用户属性对象
PersonProperties personProperties = peopleManager.GetPropertiesFor(userName);
mClientContext.Load(personProperties, p => p.AccountName, p => p.UserProfileProperties);
mClientContext.ExecuteQuery();
StringBuilder propertiesStr = new StringBuilder(1300);
foreach (var property in personProperties.UserProfileProperties)
{
propertiesStr.AppendLine(string.Format("{0}: {1}", property.Key.ToString(), property.Value.ToString()));
}
MessageBox.Show(propertiesStr.ToString());
}
}
}

本例的运行效果如下所示:

SharePoint 2013 开发——获取用户配置文件属性内容(User Profile)的更多相关文章

  1. SharePoint 2013 开发——开发并部署第一个APP

    博客地址:http://blog.csdn.net/FoxDave 本篇我们开始对开发APP应用程序进行了解. 本篇基于本地SharePoint环境(如果是Office 365的话会方便许多),需 ...

  2. [转载]SharePoint 2013测试环境安装配置指南

    软件版本 Windows Server 2012 标准版 SQL Server 2012 标准版 SharePoint Server 2013 企业版 Office Web Apps 2013 备注: ...

  3. SharePoint 2013 开发——概述

     博客地址:http://blog.csdn.net/FoxDave 近来阅读SharePoint 2013开发一书,带着与大家一起分享其中的内容. 部署场景: 本地部署(On-Premise D ...

  4. 【HOW】用PowerShell脚本修改用户配置文件属性显示次序

    首先将如下脚本保存为PowerShell文件,如:ReorderUserProfileProperty.ps1. 在执行此脚本时,如果不输入任何参数,将列出所有用户配置文件属性的名称和显示次序:如果只 ...

  5. 【HOW】如何允许编辑用户配置文件属性

    在自定义用户配置文件属性后会发现,通过属性本身的配置页面,只能允许用户修改自己的属性,而管理员无法修改其他用户的属性.若要允许管理员在用户信息页面修改用户配置文件属性,可通过如下操作实现: 1. 进入 ...

  6. SharePoint 2013+ Sqlserver 2014 Kerberos 配置传奇, 最终的解决方案 验证。

    SharePoint 2013+ Sqlserver 2014 Kerberos 配置传奇. 1,安装数据库,我就不多说安装,客户一定要注意. 我将参照以下实施例和账户. 2,建立DNS,假设没有DN ...

  7. sharepoint 2013 更改用户配置文件属性值的方法 modify user profile

    在此前写了两篇文章sharepoint 的UserProfile博客 sharepoint 2010 获取用户信息UserProfile方法 sharepoint 2010 怎样用SocialComm ...

  8. SharePoint 2013 开发——Provider-hosted APP准备工作

    博客地址:http://blog.csdn.net/FoxDave 后续的内容我们来一步一步开发一个SharePoint Porvider-hosted APP,本篇主要介绍一些准备工作. Sha ...

  9. SharePoint 2013开发入门探索(一)- 自定义列表

    在SharePoint 2013中创建自定义列表的方式有很多,在网站内容页面添加应用程序就可以创建(站点内容-〉 您的应用程序),也可以通过SharePoint Designer 2013创建,而本文 ...

随机推荐

  1. 不能上传文件 unknown error happened

    做一件事情: 1 找出问题,发现问题,2 搜索问题,3 找到答案,验证之.4 找不到答案,想出思路,验证....5 不断想,记录笔记.

  2. phalcon: 表单

    以实例为说明: controller <?php use \Phalcon\Forms\Form; use \Phalcon\Forms\Element\Text; use \Phalcon\F ...

  3. 能源项目xml文件 -- app-datasource.xml

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  4. WCF技术剖析之二:再谈IIS与ASP.NET管道

    原文地址:http://www.cnblogs.com/artech/archive/2009/06/20/1507165.html 在2007年9月份,我曾经写了三篇详细介绍IIS架构和ASP.NE ...

  5. sleep函数

    Linux下: #include <unistd.h> sleep(1); // 睡眠1秒 usleep(1); // 睡眠1微妙

  6. windows下修改mysql用户名和密码

    1.关闭正在运行的MySQL. 2.打开DOS窗口,转到mysql\bin目录. 3.输入mysqld-nt --skip-grant-tables回车.如果没有出现提示信息,那就对了. 4.再开一个 ...

  7. Eclipse添加jsp页面后引入java指令报错解决方法

    新建jsp页面老提示: Multiple annotations found at this line: - The superclass "javax.servlet.http.HttpS ...

  8. #ifdef __cplusplus extern "C"

    #ifdef __cplusplus extern "C" { #endif //一段代码 #ifdef __cplusplus } #endif首先,__cplusplus是cp ...

  9. c# 中的委托以及匿名方法lambda

    1.委托的定义internal delegate int MyAddFunDe(int a,int b)2.匿名方法1)MyAddFunDe fun = delegate(int a,int b){  ...

  10. vs2016 vsto excel addin deploy error: vsto 无法解析属性type的值

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/ea33e391-21d7-4f54-92cb-c7af72f19c61/outlook- ...