
Modifying List Items
83
FIGURE410: Result output of the GetListItems() code
MODIFYING LIST ITEMS
It is great to retrieve the lists and their list items from SharePoint; however, usually you want to act
on those list items. This section continues the uses of the Lists web service and covers the processes
for creating, updating, and deleting list items.
The overall processes of creating, updating, or deleting a list item deals with a “batch” of commands
written as XML and passed to the web service (namely the
UpdateListItems() web method).
Therefore, the structure is a batch element with various methods. Each method contains the details
of the operation performed. The generic batch element structure is shown as follows:
<Batch OnError=”Continue”>
<Method ID=”1” Cmd=”{operation}“>
<Field Name=”{column name}“>{column value}</Field>
...
</Method>
<Method ID=”2”>
...
</Batch>
Each method is numbered sequentially starting at “1” and represents an operation. You may have
multiple methods within a batch element to perform multiple operations. However, for the examples
in this section, one method is used to demonstrate the particular commands.
Creating a New Item
The rst step in creating a new list item is to generate a new XmlDocument object and create the
batch element:
System.Xml.XmlDocument docNewItem = new System.Xml.XmlDocument();
System.Xml.XmlElement batchElement = docNewItem.CreateElement(“Batch”); ...