0

I have created a search webpart and implemented on a site. Webpart contains 5 fields and as of now data can be searched from a single list. I have used caml query. Can anyone provide me caml query to fetch and search data from 4 different lists in the same site. Or do I need to follow some other procedure instead of caml query. Thanks

0

You can use the site data query to make it easier, its very similar to spquery. You can give the lists by using the Lists tag with guids of the list. Example:

 using (SPSite site = new SPSite("url"))
             {
                using (SPWeb web = site.OpenWeb())
                {

               SPSiteDataQuery query = new SPSiteDataQuery();

               // Query all Web sites in this site collection. (optional)
               query.Webs = "<Webs Scope=\"SiteCollection\">";

               //Ask for all lists created from the contacts template. (use list guids here)
               query.Lists = "<Lists ServerTemplate=\"105\" />";

               // Get the Title (Last Name) and FirstName fields.
               query.ViewFields = "<FieldRef Name=\"Title\" />"; 
               query.ViewFields += "<FieldRef Name=\"FirstName\" Nullable=\"TRUE\"/>";
               DataTable results = web.GetSiteData(query);
               }
      }

here is some reference to help you:
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsitedataquery.aspx

using Lists instead of using the template :

query.Lists ="<Lists>
      <List ID='7A9FDBE6-0841-430a-8D9A-53355801B5D5' />
      <List ID='3D18F506-FCA1-451e-B645-2D720DC84FD8' />
    </Lists>";

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsitedataquery.lists(v=office.15).aspx

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.