Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Delete a document from document library using lists.asmx

  Asked By: Tanya    Date: Jan 21    Category: Sharepoint    Views: 5310

I am trying to delete a document from document library using lists.asmx.
I am calling this webservice from a webapplication as specified in one of the MSDN articles.

My code is as below.

// Create the xml command

string strBatch = "<Method ID='1' Cmd='Delete'>" +

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

"<Field Name='FileRef'>" + relativeDocumentUrl + "</Field>" +


XmlDocument xmlDoc = new System.Xml.XmlDocument();

System.Xml.XmlElement elBatch = xmlDoc.CreateElement("Batch");

elBatch.SetAttribute("OnError", "Continue");

elBatch.SetAttribute("PreCalc", "TRUE");

elBatch.SetAttribute("ViewName", System.Guid.NewGuid().ToString());

elBatch.InnerXml = strBatch;

// Executes the xml command batch

XmlNode xmlResult;

Lists spsLists = new Lists();

spsLists.Credentials = CredentialCache.DefaultNetworkCredentials;

xmlResult = spsLists.UpdateListItems(listName, batchCommand);

But I get the the following error. It doesn't have complete information as well.

System.Web.Services.Protocols.SoapException: Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown..

Can anyone help me out in solving this issue?



2 Answers Found

Answer #1    Answered By: Jaime Weaver     Answered On: Jan 21

Where’s “batchCommand” being defined?

Maybe easier if you dump the contents of the xml  you’re sending to the web  service instead of providing the code  that generates it…

Answer #2    Answered By: Damon Garner     Answered On: Jan 21

I got it working. The problem was I was trying to pass invalid viewname in the following line of the command  object.

elBatch.SetAttribut e("ViewName", System.Guid.NewGuid().ToString ());

Didn't find what you were looking for? Find more on Delete a document from document library using lists.asmx Or get search suggestion and latest updates.