I am trying to get an SPListItem object from a unique identifier (GUID). From a look at several sites (incl. 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);
However, no matter what ... It always seems to me that zero rows are returned. I do not understand why, because I know that the Guides that I use are correct.
Any ideas?
source
share