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

发布于 2024-08-03 22:43:57 字数 1452 浏览 3 评论 0原文

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

在 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 吗?文件叶参考?我应该使用文件名吗?相对路径?文件的 URL?

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

I am trying to delete an item from a list and have the following xml

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

This is returning the following error

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.

It looks like I need to provide the fileName rather than just using the ID. My attempts to do this have failed so far.

Update

I think the XML needs to be in the following format:

<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>

No error is thrown but nothing is being deleted.

Update 2

After Alex reply I removed the spaces in the url and have removed and tabs/ newlines as this "may" cause a problem:

<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>

Again no error is thrown.

Should I be using FileRef? FileLeafRef? Should I me using the file name? relative path? URL to file?

If this matters this is a Picture Libary

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

木落 2024-08-10 22:43:57

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

根据 MSDN 如何:更新列表项文章:

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

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

This is probably because there are spaces in the filename and SharePoint can't find the item. Have you tried replacing each space with %20?

According to the MSDN How to: Update List Items article:

Posting the UpdateListItems method
silently fails if a specified item
does not exist.

If this doesn't work you could try specifying the ListVersion and ViewName attributes on the Batch element. Every example I've seen specifies these.

空‖城人不在 2024-08-10 22:43:57

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

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

I recently came across the same problem, you need to include the relative path to the item you are deleting as well as the id as below:

<Batch OnError="Return">
  <Method ID="1">
    <Field Name="ID">123456</Field>
    <Field Name="FileRef">sites/library/folderNameOrFileName</Field>
  </Method>
</Batch>
爱殇璃 2024-08-10 22:43:57

您需要先通过 GetListItems 获取 ID,然后使用该 ID 作为主要事件 ID 进行删除:

System.Xml.XmlDocument docQuery = new System.Xml.XmlDocument();
XmlNode ndQuery = docQuery.CreateNode(XmlNodeType.Element, "Query", "");
XmlNode ndViewFields = docQuery.CreateNode(XmlNodeType.Element, "ViewFields", "");
XmlNode ndQueryOptions = docQuery.CreateNode(XmlNodeType.Element, "QueryOptions", "");

ndQueryOptions.InnerXml = "<IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns><DateInUtc>FALSE</DateInUtc>" ;
ndViewFields.InnerXml = "<FieldRef Name='ID'/><FieldRef Name='UID'/><FieldRef Name='Title'/>";
ndQuery.InnerXml = "<Where><Eq><FieldRef Name='UID'/><Value Type='String'>"+leaveId+"</Value></Eq></Where>";
            
System.Xml.XmlNode delNodeList = wsLists.GetListItems("Calendar","", ndQuery, ndViewFields, "", ndQueryOptions, "");

然后该 ID 包含节点 InnerXML,这里是 xml 示例:

<rs:data ItemCount="1" xmlns:rs="urn:schemas-microsoft-com:rowset">
<z:row ows_ID="5558"
ows_UID="{FC94B218-C68F-ED11-8E93-5CEA1D3BBB8C}" 
ows_Title="XXXXXXXXXXX " 
ows_MetaInfo="5558;#" 
ows__ModerationStatus="0" 
ows__Level="1" 
ows_fAllDayEvent="0" 
ows_UniqueId="5558;#{EC74D6EF-F3AD-4213-A5F0-B54EE30F86F6}" 
ows_owshiddenversion="2" 
ows_FSObjType="5558;#0" 
ows_Created="2023-01-09 10:34:12" 
ows_PermMask="0x1b03c4312ef" 
ows_Modified="2023-01-09 10:34:45" 
ows_FileRef="5558;#Lists/Calendar/5558_.000" 
xmlns:z="#RowsetSchema" />
</rs:data>

属性“ows_ID”是您可以用于删除的 ID!
以下是 GetListItems 详细信息的 MS 链接:
https:// /learn.microsoft.com/en-us/previous-versions/office/developer/sharepoint-services/ms772599(v=office.12)

You need get the ID first by GetListItems, then use this ID as primary event ID to Delete:

System.Xml.XmlDocument docQuery = new System.Xml.XmlDocument();
XmlNode ndQuery = docQuery.CreateNode(XmlNodeType.Element, "Query", "");
XmlNode ndViewFields = docQuery.CreateNode(XmlNodeType.Element, "ViewFields", "");
XmlNode ndQueryOptions = docQuery.CreateNode(XmlNodeType.Element, "QueryOptions", "");

ndQueryOptions.InnerXml = "<IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns><DateInUtc>FALSE</DateInUtc>" ;
ndViewFields.InnerXml = "<FieldRef Name='ID'/><FieldRef Name='UID'/><FieldRef Name='Title'/>";
ndQuery.InnerXml = "<Where><Eq><FieldRef Name='UID'/><Value Type='String'>"+leaveId+"</Value></Eq></Where>";
            
System.Xml.XmlNode delNodeList = wsLists.GetListItems("Calendar","", ndQuery, ndViewFields, "", ndQueryOptions, "");

Then the ID contain the node InnerXML, here is the xml sample:

<rs:data ItemCount="1" xmlns:rs="urn:schemas-microsoft-com:rowset">
<z:row ows_ID="5558"
ows_UID="{FC94B218-C68F-ED11-8E93-5CEA1D3BBB8C}" 
ows_Title="XXXXXXXXXXX " 
ows_MetaInfo="5558;#" 
ows__ModerationStatus="0" 
ows__Level="1" 
ows_fAllDayEvent="0" 
ows_UniqueId="5558;#{EC74D6EF-F3AD-4213-A5F0-B54EE30F86F6}" 
ows_owshiddenversion="2" 
ows_FSObjType="5558;#0" 
ows_Created="2023-01-09 10:34:12" 
ows_PermMask="0x1b03c4312ef" 
ows_Modified="2023-01-09 10:34:45" 
ows_FileRef="5558;#Lists/Calendar/5558_.000" 
xmlns:z="#RowsetSchema" />
</rs:data>

the attribute "ows_ID" is the ID you can use for delete!
Here is the MS link for GetListItems Details:
https://learn.microsoft.com/en-us/previous-versions/office/developer/sharepoint-services/ms772599(v=office.12)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文