当您不知道 ID 时,Sharepoint 中的批处理元素可删除列表项
我想使用 UpdateListItems Web 服务在列表中与某些条件匹配的项目时将其删除。 我不知道要删除的列表项的 ID,但知道删除条件。
例如,在 SQL 中我可以这样做:
DELETE FROM listName WHERE LastName='Bauer' AND FirstName='Jack'
您将如何编写批处理元素来执行此操作?
更新
会是这样的吗?
<Batch PreCalc='TRUE' OnError='Continue'>
<Method ID='1' Cmd='Delete'>
<Field Name='LastName'>Bauer</Field>
<Field Name='FirstName'>Jack</Field>
</Method>
</Batch>
是方法的 ID 还是您要删除的内容的 ID?
更新
我已经尝试了以下代码,返回的错误是
Invalid URL Parameter
The URL provided contains an invalid Command or Value. Please check the URL again.
我的猜测是没有 ID 就不可能完成...
I want to delete an item in a list when it matches some critera using UpdateListItems web service. I dont know the ID of the list item that I want to delete but do know the criteria.
For example in SQL I could do:
DELETE FROM listName WHERE LastName='Bauer' AND FirstName='Jack'
How would you write a Batch Element to do this?
Update
Would it be something like this?
<Batch PreCalc='TRUE' OnError='Continue'>
<Method ID='1' Cmd='Delete'>
<Field Name='LastName'>Bauer</Field>
<Field Name='FirstName'>Jack</Field>
</Method>
</Batch>
Is the ID for the Method or the ID of the thing you wish to delete?
Update
I have tried the following code and the error that is returned is
Invalid URL Parameter
The URL provided contains an invalid Command or Value. Please check the URL again.
My guessing is that it is not possible to do without the ID...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我不太熟悉使用网络服务,但我认为有一个用于搜索。 使用 API,您可以创建 SPQuery 并使用 CAML 来获取要删除的列表项。
I am not that familiar with using the web services, but I assume there is one for searching. Using the API you would create an SPQuery and use CAML to get the list items you wanted to remove.
同样,要获取从 Sharepoint 2010 对象模型返回的列表项(可在 C# 中使用)对应 xml 中关键节点的值,我们必须删除 xml 中位置 1 附加的附加字符。 这可以按如下方式完成:
// 用于解密从 SharePoint Server 2010 对象模型列表项返回的 XML 字符串的代码。 - 礼貌 - 拉吉夫·卡普尔 - Ideals.co.in。 查看 http://www.ideals.co.in/estore/code.php 完整的解决方案。
Similarly, to get list item returned from the the Sharepoint 2010 object model that can be used in C# corresponding value of a key node in xml we have to get rid of that additional character attached at position 1 in the xml. This can be done as follows:
// Code to decipher XML string returned from SharePoint Server 2010 object model list item. - Courtesy - Rajiv Kapoor - ideals.co.in. View http://www.ideals.co.in/estore/code.php for complete solution.
这看起来不可能。
我的解决方法是查询列表并获取 id。 循环响应拉出 ID,然后为每个 ID 创建一个方法来删除它。
This does not look possible.
My way round this was to query the list and get the id's. Loop for the response pull out the id's then create a method for each ID to delete it.
作为 ChrisB 答案的补充(在注释中格式化 CAML 查询似乎不起作用),您可以将查询设置为如下所示:(
这是对象模型规范,但它自然扩展到 Web 服务调用中)
然后,您将循环遍历列表项并构建批次。
As an addition to ChrisB's answer (formatting a CAML query in a comment didn't seem to work out), you'd make the query something like this:
(this is the object model specification, but it extends naturally into the webservices call)
Then you'd loop through the listitems and build up your batch.