Well, here is a simple way to do it. I am just taking an example of client server application button click. Code remains same where ever you want to use it.
Take the web service reference into your project from the SharePoint site.
protected void Button1_Click(object sender, EventArgs e)
{
Lists.Lists ListReference = new Lists.Lists();
ListReference.Credentials = System.Net.CredentialCache.DefaultCredentials;
ListReference.Url = "site_url/_vti_bin/Lists.asmx";
try
{
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
System.Xml.XmlElement elBatch = xmlDoc.CreateElement("Batch");
elBatch.SetAttribute("OnError", "Continue");
elBatch.SetAttribute("ListVersion", "1");
string strBatch = "<Method ID='1' Cmd='Delete'>" +
"<Field Name='ID'>" + "4" + "</Field></Method>";
elBatch.InnerXml = strBatch;
ListReference.UpdateListItems("List Name", elBatch);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
All we need to do is include the ID in the query. In our case, we are deleting item with the ID 4. ID is the item ID that you want to delete from the list.
Read Remove all survey response from web service for some interesting stuff.
No comments:
Post a Comment