c# - SharePoint:通过唯一 ID 获取 SPListItem

标签 c# sharepoint

我正在尝试从唯一 ID (GUID) 获取 SPListItem 对象。通过查看多个站点(包括 http://sharepoint400.blogspot.com/2011/04/using-spsitedataquery-to-find-list.htmlhttp://www.chakkaradeep.com/post/Retrieving-an-Item-from-the-RootWeb-and-Subwebs-using-its-UniqueId.aspx),我想出了下面的代码。

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 是正确的。

有什么想法吗?

最佳答案

Unique Id 的类型无效,应该是 Guid。 更新您的查询:

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

关于c# - SharePoint:通过唯一 ID 获取 SPListItem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8181506/

相关文章:

sql-server - 为什么 SharePoint 内容数据库中的 Sites.FullUrl 为空?在哪里可以找到网站集 url?

c# - 为什么我得到 "Invalid algorithm specified"异常

c# - 知道 RazorEngine 中的特定模板是否已经编译

c# - 概念: Web-enabled C# application

javascript - 来自 $rootscope 的 Angularjs 服务调用导致无休止的迭代循环

Sharepoint 2010 搜索无法抓取 mediawiki 站点

python - 如何通过Python上传本地PowerPoint文件到SharePoint目录

c# - 将 TimeSpan 数据类型转换为 DateTime?

c# - 当排除列表为空时,从 Linq 查询中排除所有结果

SharePoint 错误 : The server does not allow messages larger than 2097152 bytes