Using the list web service to insert an item into a SharePoint list can really be tricky. Since this method has the form: XML in, XML out, it can be difficult to get the parameters correctly.
First you should take a look at the list definition. It can be obtained using the GetList () method, as shown below:
XmlNode listXml = sharePointLists.GetList(listName); File.WriteAllText("listdefinition.xml", listXml.OuterXml);
The field names and their data types are important here. Field names will never be the same as the ones you see in the SharePoint GUI. A good example is the Title field, which is used for the first list field.
Now that you know this, you can create a query to migrate to SharePoint. Example:
<Batch OnError="Continue"> <Method ID="1" Cmd="New"> <Field Name="Title">Abcdef</Field> <Field Name="Project_x0020_code">999050</Field> <Field Name="Status">Open</Field> </Method> </Batch>
The Batch element is the root element of the XML. Inside you can enter different methods. They should receive a unique identifier (which is used to report errors) and a command, which can be, for example, "New" or "Update". Inside the method, you put field elements that define the value for each field. For example, the Title field gets the value "Abcdef". Be careful to use the exact name as it returns GetList ().
To execute a query in SharePoint, use the UpdateListItems () method:
XmlNode result = sharePointLists.UpdateListItems(listDefinition.Name, updates);
The return value is an XML fragment containing the status of each update. For example:
<Results xmlns="http://schemas.microsoft.com/sharepoint/soap/"> <Result ID="1,New"> <ErrorCode>0x00000000</ErrorCode> <z:row ows_ContentTypeId="0x010036F3F587127F1A44B8BA3FEFED4733C6" ows_Title="Abcdef" ows_Project_x0020_code="999050" ows_Status="Open" ows_LinkTitleNoMenu="Abcdef" ows_LinkTitle="Abcdef" ows_ID="1005" ... xmlns:z="#RowsetSchema" /> </Result> </Results>
You can analyze this and look at ErrorCode to find out which methods failed.
In practice, I created a wrapper class that takes care of all the dirty details for me. Unfortunately, this belongs to my employer, so I cannot share it with you.
This wrapper class is part of an internal utility that is used to extract information from our project database and upload it to SharePoint. Since it was developed during the company, I am not allowed to publish it here.