Sharepoint使用UpdateListItems WebService从列表中删除项目

时间:2009-09-03 11:54:35

标签: sharepoint moss wss caml

我正在尝试从列表中删除项目并使用以下xml

<Batch PreCalc='TRUE' OnError='Continue'>
    <Method ID='1' Cmd='Delete'>\
        <Field Name='ID'>185</Field>       
    </Method>
</Batch>

这将返回以下错误

0x81020030 - Invalid file name

The file name you specified could not be used.  It may be the name of
an existing file or directory, or you may not have permission to
access the file.

看起来我需要提供fileName而不仅仅是使用ID。到目前为止,我尝试这样做的尝试失败了。

更新

认为 XML需要采用以下格式:

<Batch PreCalc='TRUE' OnError='Continue'>
    <Method ID='1' Cmd='Delete'>
        <Field Name='ID'>185</Field>
        <Field Name="FileRef">http://sharepoint.mycompany.com/testsite/lib/flying spider  2009-09-03  P.jpg</Field>       
    </Method>
</Batch>

不会抛出任何错误,但没有删除任何内容。

更新2

在Alex回复后,我删除了网址中的空格并删除了标签/换行符,因为这“可能”会导致问题:

<Batch PreCalc='TRUE' OnError='Continue'>
  <Method ID='1' Cmd='Delete'>
    <Field Name='ID'>185</Field>
    <Field Name="FileRef">http://sharepoint.mycompany.com/testsite/lib/flying%20spider%202009-09-03  P.jpg</Field>
  </Method>
</Batch>

再次没有引发任何错误。

我应该使用FileRef吗? FileLeafRef?我应该使用文件名吗?相对路径?文件的URL?

如果这很重要,那就是 Picture Libary

3 个答案:

答案 0 :(得分:1)

这可能是因为文件名中有空格而SharePoint无法找到该项。您是否尝试使用%20替换每个空格?

根据MSDN How to: Update List Items文章:

  

发布UpdateListItems方法   如果指定的项目静默失败   不存在。

如果这不起作用,您可以尝试在ListVersion元素上指定ViewNameBatch属性。我见过的每个example都指明了这些。

答案 1 :(得分:1)

答案 2 :(得分:0)

我最近遇到了同样的问题,您需要包含要删除的项目的相对路径以及ID,如下所示:

<Batch OnError="Return">
  <Method ID="1">
    <Field Name="ID">123456</Field>
    <Field Name="FileRef">sites/library/folderNameOrFileName</Field>
  </Method>
</Batch>