Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        private ListItemIdList PerformMappingAndSubmit(XmlDocument doc, string siteUrl, XmlNode mapping)
        {
            ListItemIdList itemIdList = new ListItemIdList();

            Dictionary <int, XmlNode> methodMap;
            XmlNamespaceManager       nsm = GenerateBatch.BuildNamespaceManager(doc);
            ListName listName             = GetListName(mapping);


            XmlElement batch = GenerateBatch.GenerateBatchElement(doc, nsm, mapping, out methodMap);

            if (null == batch)
            {
                return(itemIdList);
            }

            itemIdList = UploadData(siteUrl, listName.ListNameToUse, batch);

            return(itemIdList);
        }