通过网络服务共享点:检查列表中是否存在项目 [英] Sharepoint via web service : checking if item exists in list

查看:43
本文介绍了通过网络服务共享点:检查列表中是否存在项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因为 Microsoft 没有包含在 sharepoint 中具有唯一约束的方法,所以这必须手动完成.

Because Microsoft did not include a way to have unique constraints in sharepoint, this has to be done manually.

我正在通过网络服务方法将项目插入共享点列表.

I am inserting items into a sharepoint list via a web service method.

如何检查是否已存在具有相同字段 ID 值的现有列表项?

How can I check if an existing list item already exists with the same field ID value?

我知道我应该使用 wsLists.getListitems Web 服务方法,但它并不完全是用户友好的".MSDN 文档在解释什么应该是一件容易的事情方面再次不是很好.

I've learnt I should be using wsLists.getListitems web service method, but its not exactly "user friendly". MSDN documentation is again not really great at explaining what should be an easy thing to do.

推荐答案

private bool itemDoesntExist()
{
    XmlDocument doc = new XmlDocument();
    doc.LoadXml("<Document><Query><Where><Contains><FieldRef Name=\"ID\" /><Value Type=\"Text\">" + this.ID  + "</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.ListName , string.Empty, listQuery, listViewFields, string.Empty, listQueryOptions, null);
    if (items.ChildNodes[1].Attributes["ItemCount"].Value == "0")
    {
        return true; 
    }
    else
    {
        return false; 
    }
}

这篇关于通过网络服务共享点:检查列表中是否存在项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆