有没有办法使用 Microsoft.SharePoint.Client 命名空间与其他用户一起创建新的列表项

Is there a way to create a new list item with other user using Microsoft.SharePoint.Client namespace

我们有一个 SharePoint 列表,其中每个用户都有权查看他创建的记录。

我的任务是编写一个生成列表项的服务, 列表项必须由服务器的经过身份验证的用户以外的其他用户创建(出于开头提到的原因),以便 "created" 项目的用户查看该项目。

问题:我们尝试了很多,但我们无法将列表项的创建者更改为除已验证的服务器用户以外的其他用户(没有抛出异常并且该项目是创建成功)。我们怎样才能做到这一点?


约束:

这是代码草稿:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;
using System.Security;
using Microsoft.SharePoint.Client.UserProfiles;
using System.Net;

namespace SharePointClientSaveWithItherUser
{
    class Program
    {
        static void Main(string[] args)
        {
            UpdateListItem();
        }

        public static void UpdateListItem()
        {
            var siteURL = "http://oportalXXXXXXXXXXXXX";
            var listName = "XXXXX";
            var createdBy = "XXXXXX";
            var modifiedBy = "XXXXXX";

            ClientContext context = new ClientContext(siteURL);

            var login = "XXXXXX";
            var password = "XXXXXX!";

            var securePassword = new SecureString();
            foreach (char c in password)
            {
                securePassword.AppendChar(c);
            }


       //     SharePointOnlineCredentials credentials = new SharePointOnlineCredentials(login, securePassword);
            context.Credentials = new NetworkCredential(login, securePassword, "XXXX"); ;

            List list = context.Web.Lists.GetByTitle(listName);
            FieldUserValue author = GetUsers(context, createdBy);
            FieldUserValue editor = GetUsers(context, modifiedBy);
            ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
            ListItem oListItem = list.AddItem(itemCreateInfo);
            oListItem["Title"] = "TEST";
            oListItem["Author"] = author; // its not working the creator of the record is the authanticated user and not the author 
           // oListItem["Editor"] = editor;

            oListItem.Update();
            context.ExecuteQuery();
        }

        //get user by username
        public static FieldUserValue GetUsers(ClientContext clientContext, string UserName)
        {

            FieldUserValue _userValue = new FieldUserValue();

            User _newUser = clientContext.Web.EnsureUser(UserName);

            clientContext.Load(_newUser);

            clientContext.ExecuteQuery();

            _userValue.LookupId = _newUser.Id;

            return _userValue;

        }
    }
}

你可以简单地使用EnsureUser方法,将用户的邮箱地址(user.name@domain.com)或域名(i:0#.w|domain\username)传递给它来解析用户,然后分配给它到作者字段。:

ListItem item = list.AddItem(itemCreateInfo);
//use email address of user or login name
var emailAddress = "user.name@tenantname.com"  //or  i:0#.w|domain\username;

var user = context.Web.EnsureUser(emailAddress);
context.Load(user);
context.ExecuteQuery();

ListItem oListItem = list.AddItem(itemCreateInfo);
oListItem["Title"] = "TEST";
oListItem["Author"] = user;                    

oListItem.Update();
context.ExecuteQuery();