SharePoint:按唯一ID获取SPListItem

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

const string QueryFormat = @"   {0}  "; SPSiteDataQuery query = new SPSiteDataQuery(); query.Webs = ""; query.Lists = ""; query.Query = string.Format(QueryFormat, itemUniqueId); query.RowLimit = 1; //query.ViewFields = ""; var results = SPContext.Current.Web.GetSiteData(query); 

但是,无论如何……我似乎总是得到零行返回。 我不明白为什么,因为我知道我使用的Guids是正确的。

有任何想法吗?

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

    {0}   

请尝试删除QueryFormat字符串中的所有空格。 使用这样的东西:

 "{0}" 

SharePoint不喜欢这些空间。

我还建议使用其中一个库生成Caml查询,如: http : //camldotnet.codeplex.com/或http://camlex.codeplex.com/