title: SharePoint: Get SPListItem by Unique ID
body: <p>I am attempting to get an SPListItem object from a unique ID (GUID). From looking at several sites (inc. <a href="http://sharepoint400.blogspot.com/2011/04/using-spsitedataquery-to-find-list.html" rel="nofollow">http://sharepoint400.blogspot.com/2011/04/using-spsitedataquery-to-find-list.html</a> and <a href="http://www.chakkaradeep.com/post/Retrieving-an-Item-from-the-RootWeb-and-Subwebs-using-its-UniqueId.aspx" rel="nofollow">http://www.chakkaradeep.com/post/Retrieving-an-Item-from-the-RootWeb-and-Subwebs-using-its-UniqueId.aspx</a>) I came up with the code below.</p>
  
  <pre><code>const string QueryFormat =
  @"&lt;Where&gt;
      &lt;Eq&gt;
          &lt;FieldRef Name='UniqueId' /&gt;
          &lt;Value Type='Lookup'&gt;{0}&lt;/Value&gt;
      &lt;/Eq&gt;
  &lt;/Where&gt;";
  
              SPSiteDataQuery query = new SPSiteDataQuery();
              query.Webs = "&lt;Webs Scope='SiteCollection' /&gt;";
              query.Lists = "&lt;Lists BaseType='0'/&gt;";
              query.Query = string.Format(QueryFormat, itemUniqueId);
              query.RowLimit = 1;
              //query.ViewFields = "&lt;FieldRef Name='WebID' /&gt;&lt;FieldRef Name='ListID' /&gt;&lt;FieldRef Name='ID' /&gt;";
  
              var results = SPContext.Current.Web.GetSiteData(query);
  </code></pre>
  
  <p>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.</p>
  
  <p>Any ideas?</p>