【问题标题】:Error:"The user doesn't exist or is not unique" in sharepoint Adding user using CSOM错误:sharepoint 中的“用户不存在或不是唯一的”使用 CSOM 添加用户
【发布时间】:2020-01-04 05:39:22
【问题描述】:

我正在尝试使用 CSOM 将用户添加到 SharePoint 网站,但我收到一条说明“用户不存在或不是唯一的”我的登录名有问题吗?。 “anil@developer19.onmicrosoft.com”是该组织的活跃用户。

using System;
using System.Security;
using Microsoft.Online.SharePoint.TenantAdministration;
using Microsoft.SharePoint.Client;
namespace CreateSiteCollections
{
    class Program
    {
        static void Main(string[] args)
        {
           //Opens the Admin URL 
            using (ClientContext ctx1 = new ClientContext("https://developer19.sharepoint.com/sites/codesite"))
            {
                //Authenticating with Tenant Admin
                SecureString passWord = new SecureString();
                foreach (char c in "Password".ToCharArray())
                    passWord.AppendChar(c);
                ctx1.Credentials = new SharePointOnlineCredentials("kailash@developer19.onmicrosoft.com", passWord);
                        GroupCollection cg = ctx1.Web.SiteGroups;
                        Group oGroup = cg.GetById(14);

                        UserCreationInformation user = new UserCreationInformation();
                        user.Email = "anil@developer19.onmicrosoft.com";
                        user.LoginName = "developer19/anil";
                        user.Title = "Anil";
                        User oUser = oGroup.Users.Add(user);
                        ctx1.ExecuteQuery();
            }
      }
   }
}

【问题讨论】:

    标签: c# .net sharepoint office365 csom


    【解决方案1】:

    我在 http://www.codesharepoint.com/csom/add-user-to-site-group-in-sharepoint-using-csom 上学到了其他方法,而不是尝试这些整个步骤。但是您可以同时使用 GetByName 或 GetById。

    Group oGroup = ctx.Web.SiteGroups.GetByName("NewCSOM Group");
                    User oUser = ctx.Web.EnsureUser("anil@developer19.onmicrosoft.com");
                    oGroup.Users.AddUser(oUser);
                    ctx.ExecuteQuery();
    

    【讨论】:

      【解决方案2】:

      可以使用 Rest API 检查用户的登录名:

      siteurl/_api/web/siteusers

      所以对于 UserCreationInformation 类,更新有效的登录名将起作用:

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-08-10
        • 2010-11-04
        • 1970-01-01
        • 2020-07-02
        • 2017-04-04
        • 2021-10-19
        • 2020-08-14
        • 1970-01-01
        相关资源
        最近更新 更多