Delete Document From SharePoint 2010 via SOAP Web Services - UpdateListItems

Delete a document from SharePoint 2010. You NEED both the ID and the FileRef.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// Delete the sharepoint document
System.Text.StringBuilder oSb = new System.Text.StringBuilder();
oSb.Append("     <Batch OnError=\"Continue\"> ");
oSb.Append("         <Method ID=\"1\" Cmd=\"Delete\"> ");
oSb.Append("             <Field Name=\"ID\">" + fileID + "</Field> ");
oSb.Append("             <Field Name=\"FileRef\">" + URLofFile + "</Field> ");
oSb.Append("        </Method>");
oSb.Append("    </Batch>");

string sResult = oSb.ToString();
XmlDocument CAMLqueryXML = new XmlDocument();
CAMLqueryXML.LoadXml(sResult);

// Execute GetListItems
XmlNode queryResults = lists.UpdateListItems(SPLibraryName, CAMLqueryXML);