【发布时间】:2020-01-06 16:05:37
【问题描述】:
我的 Office 365 组织中有 4000 多个用户,我希望使用 CSOM 将所有这些用户添加到我的 C# 中的 SharePoint 子网站。我知道我可以使用 PowerShell 代码来实现这一点,但我想使用 CSOM 在 C# 中做到这一点。我可以通过以下代码添加特定用户,但是如何在一个代码中添加所有 4000 多个用户?有没有办法在一个包含所有 4000 多个用户的循环中迭代一个对象?
using System;
using System.Security;
using Microsoft.Online.SharePoint.TenantAdministration;
using Microsoft.SharePoint.Client;
namespace Basic_Site_Subsite_Group_User_Creation
{
class Program
{
static void Main(string[] args)
{
//Opens the Admin URL
using (ClientContext ctx = new ClientContext("https://developer19.sharepoint.com/sites/Created_with_Communication_site"))
{
//Authenticating with Tenant Admin
SecureString password = new SecureString();
foreach (char c in "password".ToCharArray())
password.AppendChar(c);
ctx.Credentials = new SharePointOnlineCredentials("kailash@kailash.cf", password);
Group gru = ctx.Web.SiteGroups.GetByName("subsite1");
User use = ctx.Web.EnsureUser("anil@kailash.cf");
gru.Users.AddUser(use);
ctx.ExecuteQuery();
【问题讨论】:
标签: c# .net sharepoint office365 csom