且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将列表中的元数据列值复制到Sharepoint Online中的查找列

更新时间:2023-01-30 20:49:27

托管元数据列和查阅列是不同类型对于列,您应该创建托管元数据列而不是查找列。

然后,您可以尝试使用以下CSOM代码复制值。

string UserName = "lee@domain.onmicrosoft.com"; //give your username here  
            string password = "pw"; //give your password  
            var secure = new SecureString();
            foreach (char c in password)
            {
                securePassword.AppendChar(c);
            }

            string SourceSiteCollectionurl = "https://domain.sharepoint.com/sites/tst";
            using (var sourceContext = new ClientContext(SourceSiteCollectionurl))
            {
                sourceContext.Credentials = new SharePointOnlineCredentials(UserName, secure);
                List SourceList = sourceContext.Web.Lists.GetByTitle(listName);
                Microsoft.SharePoint.Client.ListItem item = SourceList.GetItemById(1);
                sourceContext.Load(item);
                sourceContext.ExecuteQuery();
                TaxonomyFieldValueCollection sourceValue = item["Related_x0020_Party"] as TaxonomyFieldValueCollection;
                string[] termValuesarrary;
                List<string> termValues = new List<string>();
                foreach (TaxonomyFieldValue taxProductFieldValue in sourceValue)
                {
                    termValues.Add(taxProductFieldValue.Label + "|" + taxProductFieldValue.TermGuid);
                }
                termValuesarrary = termValues.ToArray();
                string strtermValues = string.Join(";", termValuesarrary);
                List targetList = sourceContext.Web.Lists.GetByTitle("Project Department");
                Microsoft.SharePoint.Client.ListItem targetItem = targetList.GetItemById(2);
                sourceContext.Load(targetList.Fields);
                sourceContext.Load(targetItem);
                sourceContext.ExecuteQuery();
                targetItem["Related_x0020_Party"] = strtermValues;
                targetItem.Update();
                sourceContext.Load(targetItem);
                sourceContext.ExecuteQuery();
            }

以下是供您参考的主题。

https://sharepoint.stackexchange.com/questions/210550/copy-taxonomy-column-from-one-listitem-to-another-listitem

最诚挚的问候,

Lee