I'm using SPSiteData query to fetch the list items from different list as you can see below:

 SPWeb web = SPContext.Current.Web;
             SPSiteDataQuery query = new SPSiteDataQuery();
    query.Lists = "<Lists ServerTemplate=\"105\" />";
    query.ViewFields = "<FieldRef Name=\"Title\" />" +
                                "<FieldRef Name=\"FirstName\" Nullable=\"TRUE\" Type=\"Text\"/>";
    query.Query = "<OrderBy>" + 
                               "<FieldRef Name=\"Title\" />" + 
    query.Webs = "<Webs Scope=\"SiteCollection\" />";

Now after applying the spsitedata query, i want to cast the items in SplistItemCollection. Like this, how we use to do for single list.

SPList list = web.Lists["List1"];
            SPListItemCollection queryResults = list.GetItems(query);

How can i achieve this ? Any kind of help on this will be appreciated.

  • The result of a SPSiteDataQuery can not be cast to an SPListItemCollection Jul 29, 2016 at 11:42
  • is there any way where i can cast them ?
    – Muskan
    Jul 29, 2016 at 12:26

1 Answer 1


SPSiteDataQuery returns result in DataTable. and then you have to manipulate results. if you want to get listitemcollection then you have to loop through all webs in sitecollection using spquery and merge the results.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.