问题描述
我的情况是,我需要添加用于共享点组.
my scenario, I needs to add used to sharepoint group.
如果用户在站点中可用(用户信息列表),我可以使用客户端人员选择器控件来获取用户列表.
I can able go get the user list using client side people picker control if the user is available in the site (user information list).
如果该用户不存在于站点中,则无法获取该用户.
if the user is not exist in the site I can not able to get the user.
我们如何使用客户端人员选择器从AD中获取用户.
how can we get the user from AD using client side people picker.
还有其他方法可以使用客户端代码来获取AD用户并添加到共享点组中.
Is there anyother way to fetch the AD users and add into the sharepoint group using client side codes.
推荐答案
您可以调用客户端对象模型或服务器端对象模型提供的suresureUser方法,然后将用户添加到SharePoint组.
示例代码:
function AddUserToSharePointGroup() {
var clientContext = new SP.ClientContext.get_current();
var siteGroups = clientContext.get_web().get_siteGroups();
var web = clientContext.get_web();
spGroup = siteGroups.getByName(document.getElementById('groupName').value);
user = web.ensureUser(document.getElementById('name').value);
var userCollection = spGroup.get_users();
userCollection.addUser(user);
clientContext.load(user);
clientContext.load(spGroup);
clientContext.executeQueryAsync(onQuerySucceeded, onQueryFailed);
}
using(SPSite site=new SPSite("http://sharepoint.crescent.com"))
{
using (SPWeb web = site.RootWeb)
{
string GroupName="SharePoint Members";
SPGroup group = web.Groups[GroupName];
SPUser user = web.EnsureUser("Crescent\\Salaudeen");
group.AddUser(user);
web.Update();
}
}
您可以在下面的线程中查看更多详细信息.
https://msdn.microsoft.com/en-us/library/office/jj245233 .aspx
http://www.c-sharpcorner.com /blogs/how-to-to-add-users-sharepoint-group-using-jsom
http://www.sharepointdiary.com/2013/04/add-user-to-sharepoint-site-group-programmatically.html
最好的问候,
Lee
这篇关于如何使用Sharepoint客户端人员选择器从ActiveDirectory中获取用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!