示例#1
0
        private ListItemIdList UploadData(ClientContext context, string siteUrl, string listName, XmlElement batch)
        {
            XmlNodeList batchNodes = batch.SelectNodes("Method");
            int         id         = int.MinValue;

            ListItemIdList itemIdList = new ListItemIdList();
            List           spList     = context.Web.Lists.GetByTitle(listName);

            foreach (XmlNode newNode in batchNodes)
            {
                string   command = newNode.SelectSingleNode("@Cmd").InnerText;
                ListItem item    = null;

                if (command == "New")
                {
                    ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
                    item = spList.AddItem(itemCreateInfo);
                }
                else if (command == "Update")
                {
                    XmlNode idNode = newNode.SelectSingleNode("Field[@Name='ID']");
                    id   = Convert.ToInt32(idNode.InnerText);
                    item = spList.GetItemById(id);
                }

                UpdateListItemFields(item, newNode);
                item.Update();
                AddAttachments(item, newNode);
                item.Update();
                context.ExecuteQuery();
                itemIdList.Add(new ListItemId(id > int.MinValue ? id : item.Id));
            }
            return(itemIdList);
        }