0

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\" />" + 
                           "</OrderBy>";
    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 – Robert Lindgren Jul 29 '16 at 11:42
  • is there any way where i can cast them ? – Muskan Jul 29 '16 at 12:26
0

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, privacy policy and cookie policy

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