I have one site collection that is RootSite. Two sub sites that are subSite1 and subSite2.

subSite1 has list EMP_info with columns Title and Dept.

subSite2 has list DEPT_info with columns Title and Dept_ID.

I want to show list EMP_info and DEPT_info on RootSite in a Visual Web Part.

I implemented it by using SPSiteDataQuery, writing two separate queries. But how is it possible to write it using a single query?

If there are 1000 sub sites and 1000 lists with same column name, then how it is possible to get that 1000 list using a single query?

  • Mohsin - add a tag specifying the SharePoint Version – spStacker Aug 20 '15 at 13:42

I believe we should we able to pull all the list under one sitecollection using only one query.

For Instance,

If all the list that you are looking to pull the data are custom List then set

query.Lists = "<Lists ServerTemplate=\"100\" MaxListLimit=\"0\" />";

The threshold of how many list's can be returned. It has been answered here. By default the Limit is 1000, but if you mention 0, then there will be no limit set, and thus all the lists will be return.

Set the web scope to Site Collection

query.Webs = "<Webs Scope=\"SiteCollection\" />";

Since SubSite1 and SubSite2 falls under RootSite, it should be able to pull all the list under the site collection.

Follow this msdn article for more insights.

  • If all list having same column name? – Mohsin Aug 21 '15 at 5:10

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.