我能够删除使用这段代码列表中的文档的SharePoint列表的文件:如何更新使用UpdateListItems
// 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;
}
}
正如你所看到的,我必须指定fileRef,这将告诉sharepoint哪个文件,我想删除。
但是,我无法以同样的方式更新列表的文档名称。没有错误返回,名称不会改变。
“列表”Web服务凭据非常正确。这就是我能够保护的东西。 fileRef中指定的文档也是正确的。
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;
}
}
我很好奇这里的例子:http://msdn.microsoft.com/en-us/library/lists.lists.updatelistitems.aspx,因为我不知道在哪里指定文件(其GUID或其fileRef),既可用于更新和删除。 Sharepoint如何知道哪些文档应该被删除/更新?
我在做什么错误或误解的东西?
任何人都可以成功地更新文档,请分享您的工作。 感谢
精确重复数据删除的ID设置项的属性://计算器。 com/questions/994173/how-do-i-rename-a-file-using-the-sharepoint-web-services – 2009-08-19 09:11:27
谢谢Alex。这就是我要找的。它为我工作。我发现的是文件/文件的ID必须在ID字段中指定。 – tata9999 2009-08-21 06:49:23