Sharepoint:通过网络服务检查共享点列表子文件夹中是否存在项目?
我原来的问题此处回答了如何检查如果列表中存在某个项目,但这不适用于列表中子文件夹中的项目。
如何检查某个项目是否存在,无论其存储在哪个子文件夹中?
如果失败,我如何检查项目是否存在,即使这意味着以某种方式将子文件夹值传递给查询?
以下代码有效,但不会在子文件夹中查找:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将范围设置为递归
您可以使用对象模型 SPQuery.ViewAttributes
看起来您正在使用 Web 服务 GetListItems,因此您可以在 查询选项
You need to set the Scope to Recursive
You can do this using the object model SPQuery.ViewAttributes
Looks like you are using the web service GetListItems so you would pass this param in QueryOptions