2

我正在尝试从列表中删除一个项目并具有以下 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.

看起来我需要提供文件名而不仅仅是使用 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

在亚历克斯回复后,我删除了 url 中的空格并删除了制表符/换行符,因为这个“可能”会导致问题:

<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? 我应该使用文件名吗?相对路径?文件的网址?

如果这很重要,这是一个图片库

4

3 回答 3

1

这可能是因为文件名中有空格,SharePoint 找不到该项目。您是否尝试过用 替换每个空格%20

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

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

如果这不起作用,您可以尝试在元素上指定ListVersionandViewName属性。我见过的Batch每个例子都指定了这些。

于 2009-09-03T13:05:20.163 回答
1

也试试这个

从 SharePoint 列表中删除项目等

于 2009-10-06T05:26:01.247 回答
1

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

<Batch OnError="Return">
  <Method ID="1">
    <Field Name="ID">123456</Field>
    <Field Name="FileRef">sites/library/folderNameOrFileName</Field>
  </Method>
</Batch>
于 2014-03-24T10:58:31.237 回答