Thursday, January 21, 2010

SharePoint Web Service(2)--Update and Delete a List Item

In previous post, I simply introduced that how to use SharePoint Web Service to create a new item in a List. Since we can create a new item, we should be able to update and delete item in a list. Actually, the code for updating is similar to the code for deleting.

Updating

batch.InnerXml = "<Method ID='1' Cmd='Update'>" +  

       
"<Field Name='ID'>New</Field>" +  

       
"<Field Name='Title'>Something</Field>" +  



       "<Field Name='SomeField'>Something Else</Field></Method>";

There is only one difference comparing to previous post, the value of the attribute "Cmd". The value is "New" in previous post. Now you only need change it to "Update". You should pay attention to the ID field, you need specify this field.
Deleting
batch.InnerXml = "<Method ID='1' Cmd='Delete'>" +  


       "<Field Name='ID'>New</Field>" +  </Method>";
Deleting is very simple. You only need change the Cmd value to "Delete", and provide the ID of item you want to delete.
After you call the service operation, it would return a XML snippet containing the information if the operation is successful or not.

No comments:

Post a Comment