7

SharePoint CSOM 处理人员和组字段

 3 years ago
source link: https://www.cnblogs.com/jianyus/p/14508294.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

SharePoint CSOM 处理人员和组字段

  前言

  最近,在做SharePoint Online 数据迁移的工作,于是乎,就有了处理人员和组字段的需求。

  正文

  首先,需要获取字段的值未FieldUserValue[]类型,然后,每个用户都需要在新站点EnsuerUser一下,确保在新站点上已经存在。

if (sourceItem.FieldValues["Users"] != null)
{
FieldUserValue[] fUsers1 = sourceItem.FieldValues["Users"] as FieldUserValue[];
FieldUserValue[] users1 = new FieldUserValue[fUsers1.Length];
for (int m = 0; m < fUsers1.Length; m++)
{
    try
    {
        User TempUser = targetWeb.EnsureUser(fUsers1[m].Email);
        targetContext.Load(TempUser);
        targetContext.ExecuteQuery();
        FieldUserValue fieldUserVal = new FieldUserValue();
        fieldUserVal.LookupId = TempUser.Id;
        users1.SetValue(fieldUserVal, m);
    }
    catch{}
}

newItem["Users"] = users1;
newItem.Update();
targetContext.ExecuteQuery();
}

  结束语

  其实,在处理的过程中,还需要判断其中是否有User已经不在Talent里了的情况,防止程序报错。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK