I'm able to delete a document in a list using this piece of code:
// string fileRef = "folder/myplan.doc"
private void DeleteDocument(string fileRef, string listGuid)
{
string strBatch = "<Method ID=\"1\" Cmd=\"Delete\">" +
"<Field Name=\"ID\">1</Field>" +
"<Field Name=\"FileRef\">" + fileRef + "</Field>" +
"</Method>";
XmlDocument xmlDoc = new System.Xml.XmlDocument();
System.Xml.XmlElement elBatch = xmlDoc.CreateElement("Batch");
elBatch.SetAttribute("OnError", "Continue");
elBatch.SetAttribute("ListVersion", "1");
elBatch.InnerXml = strBatch;
try
{
XmlNode ndReturn = lists.UpdateListItems(listGuid, elBatch);
}
catch (Exception ex)
{
throw ex;
}
}
As you can see, i have to specify the fileRef, this will tell sharepoint which file i would want to delete.
However, i'm not able to update the document name of a list the same way. There is no error returned, the name just doesn't get changed.
The credentials for "lists" web service is quite correct. That's what i can guaratee. The document specified in fileRef is correct too.
private void UpdateDocument(string fileRef, string listGuid, string newName)
{
string strBatch = "<Method ID=\"1\" Cmd=\"Update\">" +
"<Field Name=\"ID\">1</Field>" +
"<Field Name=\"Title\">" + newName + "</Field>" +
"<Field Name=\"FileRef\">" + fileRef + "</Field>" +
"</Method>";
XmlDocument xmlDoc = new System.Xml.XmlDocument();
System.Xml.XmlElement elBatch = xmlDoc.CreateElement("Batch");
elBatch.SetAttribute("OnError", "Continue");
elBatch.SetAttribute("ListVersion", "1");
elBatch.InnerXml = strBatch;
try
{
XmlNode ndReturn = lists.UpdateListItems(listGuid, elBatch);
}
catch (Exception ex)
{
throw ex;
}
}
I'm curious about the examples here: http://msdn.microsoft.com/en-us/library/lists.lists.updatelistitems.aspx because i don't see where to specify the document (its guid or its fileRef), both for update and delete. How sharepoint knows which document should be deleted/updated?
I'm doing anything wrong or misunderstanding something?
Anyone has ever been successful in updating a document please share your work. Thanks