我能够成功更新列表项,但是当我尝试删除一个项目时,我得到以下响应:
InnerXml = "<Result ID=\"1,Delete\" xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\"><ErrorCode>0x00000000</ErrorCode></Result>"
InnerText = "0x00000000"
这似乎表明成功,但文件仍然存在!
下面是代码:(代码与编辑现有项目相同,除非另有说明)变量:
pID = The SharePoint ID of the list item document.
pFileName = The passed in filename (e.g.: "John Doe Capital.pdf"
pInternalID = An internal ID that is combined with the document in SharePoint (e.g.: 1187)
string lListName = ConfigurationManager.AppSettings["SharepointPipelineDocsList"];
XmlNode lSharePointListName = mSharepointListsService.GetList(lListName);
string lListID = lSharePointListName.Attributes["ID"].Value; // Provides the GUID id for the actual list
XmlDocument xmlDoc = new System.Xml.XmlDocument();
System.Xml.XmlElement elBatch = xmlDoc.CreateElement("Batch");
elBatch.SetAttribute("OnError", "Continue");
string strBatch = string.Empty;
// Construct file url - this is only used with DELETE
string lFileName = StripExtensionFromFile(pFileName); // Private method that strips off extension.
lFileName = pInternalID + "-" + lFileName;
string lUrlPrefix = ConfigurationManager.AppSettings["SharepointPipelinesiteUrl"];
string lDestinationUrl = lUrlPrefix
+ "/" + lListName
+ "/" + lFileName;
// Indicate file to be deleted. This is only used with DELETE
strBatch = "<Method ID='1' Cmd='Delete'>" +
"<Field Name='ID'>" + pID + "</Field>" +
"<Field Name='FileRef'>" + lDestinationUrl + "</Field></Method>";
elBatch.InnerXml = strBatch;
XmlNode ndReturn = mSharepointListsService.UpdateListItems(lListID, elBatch);
我读到删除命令需要文档 ID 值和文件 url。我确信问题一定出在 CAML 上。这是 strBatch 的示例值:
strBatch "<Method ID='1' Cmd='Delete'><Field Name='ID'>980</Field><Field Name='FileRef'>http://intranetdev/finops/Investment Documents/1187-Test - 4</Field></Method>"
也许是文件 url 中的空格?
任何智慧将不胜感激。