使用UpdateListItems删除SharePoint文件返回成功但文件仍然存在

时间:2013-06-06 19:12:15

标签: c# sharepoint whitespace listitem delete-file

我能够成功更新列表项,但当我尝试删除项时,我得到以下响应:

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中的空格?

任何智慧都会受到高度赞赏。

0 个答案:

没有答案