csharp 使用SharePoint客户端对象模型从SharePoint用户配置文件服务获取信息。这使用了对Profile DB的查询
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 使用SharePoint客户端对象模型从SharePoint用户配置文件服务获取信息。这使用了对Profile DB的查询相关的知识,希望对你有一定的参考价值。
Console.WriteLine("Gathering profile data");
List<ProfileData> lstData = new List<ProfileData>();
ClientContext cix = new ClientContext("http://scushp01");
cix.Credentials = new NetworkCredential("scu\\SVCSPProfileReader", "bacrEm7S");
cix.ExecuteQuery();
PeopleManager peopleManager = new PeopleManager(cix);
string strConnectionString = @"Password=bacrEm7S;Persist Security Info=True;User ID=scuProfileReader;Initial Catalog=Profile DB;Data Source=scusql5\scusp";
string strQuery = "SELECT * FROM vw_UserProfile_AccountNames";
SqlConnection sc = new SqlConnection(strConnectionString);
SqlCommand queryCommand = new SqlCommand(strQuery, sc);
sc.Open();
SqlDataReader dr = queryCommand.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
foreach (DataRow item in dt.Rows)
{
string strAcctName = item.Field<string>("AccountName");
PersonProperties personProperties = peopleManager.GetPropertiesFor(strAcctName);
cix.Load(personProperties);
cix.ExecuteQuery();
ProfileData pd = new ProfileData();
foreach (var property in personProperties.UserProfileProperties)
{
//Console.WriteLine(string.Format("{0}: {1}",property.Key.ToString(), property.Value.ToString()));
switch (property.Key.ToString())
{
case "HDate":
DateTime result;
if (DateTime.TryParse(property.Value.ToString(), out result))
{
pd.HireDate = result;
}
break;
case "BDate":
if (property.Value.ToString() != "")
{
DateTime datBdate = DateTime.Parse(property.Value.ToString() + "-" + DateTime.Now.Year.ToString());
pd.BirthDate = datBdate;
}
break;
case "FirstName":
pd.firstName = property.Value.ToString();
break;
case "LastName":
pd.lastName = property.Value.ToString();
break;
}
}//end of the for each properties
lstData.Add(pd);
Console.WriteLine("Gathered profile for:" + pd.firstName + " " + pd.lastName);
}//end of the foreach db rows
return lstData;
}//end of function
以上是关于csharp 使用SharePoint客户端对象模型从SharePoint用户配置文件服务获取信息。这使用了对Profile DB的查询的主要内容,如果未能解决你的问题,请参考以下文章
csharp 使用SharePoint客户端对象模型从SharePoint用户配置文件服务获取信息。这使用了对Profile DB的查询
csharp 此代码段提升了用户的权限,以便从SharePoint对象模型执行某些操作。只有在Elev中声明的项目
csharp 使用CSOM创建Sharepoint Wiki页面
csharp 使用列名称中的CAML获取SharePoint项目(SPListItem)。
csharp 此控制台应用程序测试是否在SharePoint中使用内容类型
BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第2章节--SharePoint 2013 App 模型概览 SharePoint 2013 App 模