Sharepoint:通过网络服务检查共享点列表子文件夹中是否存在项目?

发布于 2024-08-09 20:32:14 字数 1222 浏览 1 评论 0原文

我原来的问题此处回答了如何检查如果列表中存在某个项目,但这不适用于列表中子文件夹中的项目。

如何检查某个项目是否存在,无论其存储在哪个子文件夹中?

如果失败,我如何检查项目是否存在,即使这意味着以某种方式将子文件夹值传递给查询?

以下代码有效,但不会在子文件夹中查找:

private bool attachmentLinkItemDoesntExist(string attachmentName)
{
    XmlDocument doc = new XmlDocument();
    doc.LoadXml("<Document><Query><Where><Contains><FieldRef Name=\"Title\" /><Value Type=\"Text\">" +  this.downloadedMessageID + "_" + attachmentName + "</Value></Contains></Where></Query><ViewFields /><QueryOptions /></Document>");
    XmlNode listQuery = doc.SelectSingleNode("//Query");
    XmlNode listViewFields = doc.SelectSingleNode("//ViewFields");
    XmlNode listQueryOptions = doc.SelectSingleNode("//QueryOptions");
    XmlNode items = this.wsLists.GetListItems(this.AttachmentsListName , string.Empty, listQuery, listViewFields, string.Empty, listQueryOptions, null);
    if (items.ChildNodes[1].Attributes["ItemCount"].Value == "0")
    {
        return true;
    }
    else
    {
        return false;
    }
}

My original question here answers how to check if an item exists in a list, but this doesn't work for items in sub folders in the list.

How can I check if an item exists, regardless of what subfolder its stored in?

Failing this, how can I check if an item exists , even if this means somehow passing the subfolder value to the query somehow?

Following code works, but will not look in subfolders:

private bool attachmentLinkItemDoesntExist(string attachmentName)
{
    XmlDocument doc = new XmlDocument();
    doc.LoadXml("<Document><Query><Where><Contains><FieldRef Name=\"Title\" /><Value Type=\"Text\">" +  this.downloadedMessageID + "_" + attachmentName + "</Value></Contains></Where></Query><ViewFields /><QueryOptions /></Document>");
    XmlNode listQuery = doc.SelectSingleNode("//Query");
    XmlNode listViewFields = doc.SelectSingleNode("//ViewFields");
    XmlNode listQueryOptions = doc.SelectSingleNode("//QueryOptions");
    XmlNode items = this.wsLists.GetListItems(this.AttachmentsListName , string.Empty, listQuery, listViewFields, string.Empty, listQueryOptions, null);
    if (items.ChildNodes[1].Attributes["ItemCount"].Value == "0")
    {
        return true;
    }
    else
    {
        return false;
    }
}

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

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

发布评论

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

评论(1

香橙ぽ 2024-08-16 20:32:14

您需要将范围设置为递归

您可以使用对象模型 SPQuery.ViewAttributes

query.ViewAttributes = "Scope=\"Recursive\"";

看起来您正在使用 Web 服务 GetListItems,因此您可以在 查询选项

<QueryOptions>
   <ViewAttributes Scope="Recursive" />
</QueryOptions>

You need to set the Scope to Recursive

You can do this using the object model SPQuery.ViewAttributes

query.ViewAttributes = "Scope=\"Recursive\"";

Looks like you are using the web service GetListItems so you would pass this param in QueryOptions

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