Wanted to use Sharepoint's web services to manipulate a list on one of our WSS sites.
Then submit a list item from a remote location, so using the Lists web service (http://<server-url>/_vti_bin/lists.asmx) seemed to make sense.
Basically, what you submit to the web service is a xml document that contains the values for the list fields that you want to add, something like this (lifted and modified from here):
string sBatch = string.Empty;
sBatch = “<Method ID=\"1\" Cmd=\"New\">";
sBatch += “<Field Name=\"ID\">New</Field>";
sBatch += “<Field Name=\"Title\">My Title</Field>";
sBatch += “<Field Name=\"EventDate\">" + DateTime.Now + “</Field>";
sBatch += “</Method>";
This is one way to construct the xml document that you need to submit. This xml will add an item with a title of 'My Title' and an Event Date of the current date/time. This code works, theres nothing wrong with it. Its just that this is the extent of the examples out there, I couldn't find anything that was more complex, for instance, an example of inserting an item into a Sharepoint list where one of the fields in the list is a lookup to another Sharepoint list.
Consider a list where there is a Status column, which is a lookup to another list that has possible values of 'Submitted', 'Approved', 'Rejected', and 'Completed'. How do you specify the value for this field? I initially tried simply inserting the text value of what I wanted, so my xml would look like this:
<Method ID="1″ Cmd="New">
<Field Name="ID">New</Field>
<Field Name="Title">My Title</Field>
<Field Name="EventDate">3/25/2006 12:00 PM</Field>
<Field Name="Status">Submitted</Field>
</Method>
But this doesn't work. After some more trial and error, I tried the index of the value that I wanted, in this case 0, because 'Submitted' is the first item in the list, and presto! My item was inserted, all was good. The downside that I see to this, is that if the indices of the items change, you have to change your xml. You could get around this by querying the lookup list and finding the index of the item dynamically each time, its your call. So if you want to insert an item into Sharepoint with a field that is a lookup field, here is an example of what your xml should look like:
<Method ID="1″ Cmd="New">
<Field Name="ID">New</Field>
<Field Name="Title">My Title</Field>
<Field Name="EventDate">3/25/2006 12:00 PM</Field>
<Field Name="Status" Type="Lookup">0</Field>
</Method>
thanks Ben Reichelt’s Weblog