剖析SharePoint:通过唯一的ID获取SPListItem [英] SharePoint: Get SPListItem by Unique ID

查看:329
本文介绍了剖析SharePoint:通过唯一的ID获取SPListItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从一个独特的ID(GUID)得到一个SPListItem对象。通过观察几个网站(INC 的http:// sharepoint400 .blogspot.com / 2011/04 /使用-spsitedataquery找到的-list.html 和的 http://www.chakkaradeep.com/post/Retrieving-an-Item-from-the-RootWeb-and-Subwebs-利用其通UniqueId.aspx )我想出了下面的代码。

I am attempting to get an SPListItem object from a unique ID (GUID). From looking at several sites (inc. http://sharepoint400.blogspot.com/2011/04/using-spsitedataquery-to-find-list.html and http://www.chakkaradeep.com/post/Retrieving-an-Item-from-the-RootWeb-and-Subwebs-using-its-UniqueId.aspx) I came up with the code below.

const string QueryFormat =
@"<Where>
    <Eq>
        <FieldRef Name='UniqueId' />
        <Value Type='Lookup'>{0}</Value>
    </Eq>
</Where>";

            SPSiteDataQuery query = new SPSiteDataQuery();
            query.Webs = "<Webs Scope='SiteCollection' />";
            query.Lists = "<Lists BaseType='0'/>";
            query.Query = string.Format(QueryFormat, itemUniqueId);
            query.RowLimit = 1;
            //query.ViewFields = "<FieldRef Name='WebID' /><FieldRef Name='ListID' /><FieldRef Name='ID' />";

            var results = SPContext.Current.Web.GetSiteData(query);



不过,无论怎样......我似乎总是得到零行返回。我不明白为什么,因为我知道我使用的GUID是正确的。

However, no matter what... I always seem to get zero rows returned. I don't understand why, because I know the Guids I am using are correct.

任何想法?

推荐答案

有一个无效类型唯一ID应该GUID。
更新查询:

There is an invalid type for Unique Id, it should be Guid. Update your query:

<Where>
    <Eq>
        <FieldRef Name='UniqueId'/>
        <Value Type='Guid'>{0}</Value>
    </Eq>
</Where>

这篇关于剖析SharePoint:通过唯一的ID获取SPListItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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