如何使用SharePoint客户端API获取所有用户配置文件?
要实现生日SharePoint 2013应用程序,我需要从网站集中获取所有用户配置文件。为此,我想使用一个(或多个)客户端API。看 不幸的是,我在API描述中找不到与Microsoft.Office.Server.UserProfiles等效的API。如何使用SharePoint客户端API获取所有用户配置文件?,sharepoint,sharepoint-2013,Sharepoint,Sharepoint 2013,要实现生日SharePoint 2013应用程序,我需要从网站集中获取所有用户配置文件。为此,我想使用一个(或多个)客户端API。看 不幸的是,我在API描述中找不到与Microsoft.Office.Server.UserProfiles等效的API。Microsoft.SharePoint.Client.UserProfiles.PeopleManager中有两种方法,getuserprofileproperties for和getuserprofileproperty for,它们只获取一
Microsoft.SharePoint.Client.UserProfiles.PeopleManager
中有两种方法,getuserprofileproperties for
和getuserprofileproperty for
,它们只获取一个用户配置文件
所以我的问题是:如何使用CSOM、JSOM、REST(或任何客户端技术)获取网站集中的所有用户配置文件?也适用于SP2013
function GetUsersGroups(){
ClientContext context = new Microsoft.SharePoint.Client.ClientContext("http://SPSite");
GroupCollection groupCollection = context.Web.SiteGroups;
context.Load(groupCollection,
groups = > groups.Include(group = > group.Users));
context.ExecuteQuery();
foreach (Group group in groupCollection)
{
UserCollection userCollection = group.Users;
foreach (User user in userCollection)
{
MessageBox.Show("User Name: " + user.Title + " Email: " + user.Email + " Login: " + user.LoginName);
}
}
//Iterate the owners group
Group ownerGroup = context.Web.AssociatedOwnerGroup;
context.Load(ownerGroup);
context.Load(ownerGroup.Users);
context.ExecuteQuery();
foreach (User ownerUser in ownerGroup.Users)
{
MessageBox.Show("User Name: " + ownerUser.Title + " Email: " + ownerUser.Email + " Login: " + ownerUser.LoginName);
}
context.Dispose();
}
由于CSOM为每个用户范围内的人员提供了相关操作的方法,因此您可以首先使用。然后使用 要获取
生日
属性,如下所示:
//Get Birthday User Profile Property for Site Users
function getUsersBirthdays(Success,Error) {
var clientContext = new SP.ClientContext.get_current();
var web = clientContext.get_web();
var users = web.get_siteUsers();
clientContext.load(users);
clientContext.executeQueryAsync(
function() {
var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);
var personsProperties = [];
for(var i = 0; i < users.get_count();i++)
{
var user = users.getItemAtIndex(i);
var personBirthday = peopleManager.getUserProfilePropertyFor(user.get_loginName(),'SPS-Birthday');
personsProperties.push(personBirthday);
}
clientContext.executeQueryAsync(
function() {
Success(personsProperties);
},
Error);
},
Error);
}
//Usage
var scriptbase = _spPageContextInfo.webAbsoluteUrl + '/_layouts/15/';
$.getScript(scriptbase + 'SP.js', function () {
$.getScript(scriptbase + 'SP.UserProfiles.js', function () {
getUsersBirthdays(function(usersProperties){
for(var i = 0; i < usersProperties.length;i++)
{
console.log(usersProperties[i].get_value());
}
},
function(sender,args){
console.log(args.get_message());
});
});
});
//获取站点用户的生日用户配置文件属性
函数getUsersBithDays(成功,错误){
var clientContext=new SP.clientContext.get_current();
var web=clientContext.get_web();
var users=web.get_siteUsers();
clientContext.load(用户);
clientContext.executeQueryAsync(
函数(){
var peopleManager=new SP.UserProfiles.peopleManager(clientContext);
var personproperties=[];
对于(var i=0;i
谢谢你的回答,格雷格,但这对用户有效
不适用于用户档案
。我需要提取出生日期。您好@Greg,SP.UserProfiles.UserProfilePropertiesForUser
相当于Microsoft.SharePoint.Client.UserProfiles.PeopleManager.GetUserProfilePropertiesFor
。要获取所有用户配置文件,应首先检索所有用户,然后检索每个用户的相应配置文件。这对性能不太友好。我只想一次放弃几个过滤器,只得到满足这些标准的结果。谢谢@Vadim Gremyachev的回答。出于性能原因,我最终通过REST搜索查询解决了这个问题:var queryUrl=appweburl+“/”api/search/query?”+“querytext=”*“+”&sourceid='B09A7990-05EA-4AF9-81EF-EDFAB16C4E31'+“&rowlimit=500”+“&selectproperties='PreferredName,Birth'”;$。ajax({url:queryUrl,方法:“GET”,头:{“Accept”:“application/json;odata=verbose”},成功:successHandler,错误:errorHandler})代码>