I am trying to migrate SharePoint 2010 list items to an O365 list. But when the code is executed, it creates empty list items in O365 list even though "newItem" has the correct key value pair. Here "liCol" is the collection of list items in the SP2010 list.
foreach (ListItem li in liCol)
{
ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
ListItem newItem = list.AddItem(itemCreateInfo);
foreach (KeyValuePair<string, object> liField in li.FieldValues)
{
bool isFieldReadOnly = false;
string itemFieldName = liField.Key;
Field field = list.Fields.GetByTitle(itemFieldName);
c.Load(field);
c.ExecuteQuery();
isFieldReadOnly = field.ReadOnlyField;
if (!isFieldReadOnly)
{
newItem[itemFieldName] = li[itemFieldName];
}
}
newItem.Update();
}
list.Update();
c.ExecuteQuery();

0 commentaires:
Enregistrer un commentaire