Wednesday, 25 September 2013

Batch Update


 public void SaveListData()
        {
            string batchOutput = string.Empty;
            using (new SPMonitoredScope("SaveWorkflowMapData"))
            {
                string batch = string.Empty;
               
               
                    SPList contentList = taskActivityWeb.Lists.TryGetList(Convert.ToString(taskList, CultureInfo.InvariantCulture));
                    if (contentList != null)
                    {
                        string batchFormat = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                        "<ows:Batch OnError=\"Return\">{0}</ows:Batch>";
                        string methodFormat = string.Empty;
                        if (SourceListItemCollection!= null && (SourceListItemCollection!> 0)
                        {
                            foreach (SPListItem WorkflowMapData in SourceListItemCollection)
                            {
                             
                                     
                                         
                                            methodFormat += String.Format(CultureInfo.InvariantCulture, "<Method ID=\"{0}\"><SetList>{1}</SetList><SetVar Name=\"Cmd\">Save</SetVar><SetVar Name=\"ID\">New</SetVar>", counter, DestinationList.ID);
                                            methodFormat += "<SetVar Name=\"urn:schemas-microsoft-com:office:office#" + ESWSiteColumns.Title.GetDescription() + "\">" + taskNumber + "</SetVar>";
                                            methodFormat += "<SetVar Name=\"urn:schemas-microsoft-com:office:office#" + ESWTaskWorkFlowMap.TaskContentNoIn.GetDescription() + "\">" + Convert.ToString(WorkflowMapData[ESWTaskWorkFlowMap.TaskContentNoIn.GetDescription()], CultureInfo.InvariantCulture) + "</SetVar>";
                                            methodFormat += "<SetVar Name=\"urn:schemas-microsoft-com:office:office#" + ESWTaskWorkFlowMap.TaskContentVersionInt.GetDescription() + "\">" + Convert.ToInt32(WorkflowMapData[ESWTaskWorkFlowMap.TaskContentVersionInt.GetDescription()], CultureInfo.InvariantCulture) + "</SetVar>";
                                            methodFormat += "<SetVar Name=\"urn:schemas-microsoft-com:office:office#" + ESWTaskWorkFlowMap.TaskContentTitleIn.GetDescription() + "\">" + Convert.ToString(hashWorkflowData[ESWTaskWorkFlowMap.TaskContentTitleIn.GetDescription()], CultureInfo.InvariantCulture) + "</SetVar>";
                                            methodFormat += "<SetVar Name=\"urn:schemas-microsoft-com:office:office#" + ESWTaskWorkFlowMap.TaskSubWorkflowMapInt.GetDescription() + "\">" + subWorflowMap + "</SetVar>";
                                            methodFormat += "<SetVar Name=\"urn:schemas-microsoft-com:office:office#" + ESWTaskWorkFlowMap.TaskApplicabilityInt.GetDescription() + "\">" + 1 + "</SetVar>";
                                            methodFormat += "</Method>";
                                         
                                     
                            }
                           
                                batch = string.Format(CultureInfo.InvariantCulture, batchFormat, methodFormat);
                                oWeb.AllowUnsafeUpdates = true;
                                batchOutput = taskActivityWeb.ProcessBatchData(batch);
                                oWeb.AllowUnsafeUpdates = false;
                             
                                for (int i = 0; i < SourceListItemCollection.Count; i++)
                                {

                                   int savedlistitemID=Convert.ToInt32(GetResultsId(batchOutput)[i].InnerText, CultureInfo.InvariantCulture);
                                }
                         
                        }
                    }
                 
                }
             
            }
        }


        public static XmlNodeList GetResultsId(string batchOutput)
        {
            XmlDocument xmlDocument = new XmlDocument();
            xmlDocument.LoadXml(batchOutput);
            return xmlDocument.GetElementsByTagName("ID");
        }

No comments:

Post a Comment