locked
Get all Task list under site collections using share point web services RRS feed

  • Question

  • Hi

    I want efficient way  to get all Task lists under site collections(all sub sites) using share point  web services.

    Actually I dont want to go with iterate through all the sites in the site collection and queary for all lists in that site and take tasks lists from them. Looking for a query(CAML or Something else) to get required required result.

    Can any one let me know how to query share point to get all "Task" Type list using share point web services.

    Thanks in advance.

    Wednesday, January 4, 2012 9:42 PM

Answers

  • Hi KRIS_Dev,

    To get list items based on a content type under a site collection, you can use SPSiteDataQuery class, it represents a query that can be performed across multiple lists in multiple web sites in the same web site collection, to execute the query, you need to pass the SPSiteDataQuery object to the GetSiteData(SPSiteDataQuery) method, here is the document for SPSiteDataQuery class:
    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsitedataquery.aspx

    You can use the code snippet below to retrieve items form the default ‘Tasks’ or ‘Workflow Tasks’ lists with in a sub site:
    SPSiteDataQuery q = new SPSiteDataQuery();

            q.ViewFields = "<FieldRef Name='Title'/><FieldRef Name='Priority'/><FieldRef Name='Status'/>";

            q.Webs = "<Webs Scope='SiteCollection' />";

            q.Lists = "<Lists BaseType='0' />";

            q.Query = "<Where><Gt><FieldRef Name='ID' /><Value Type='Number'>0</Value></Gt></Where>";

            DataTable results = new DataTable();

            using (SPSite site = new SPSite("http://sharepoint"))

            {

                using (SPWeb web = site.OpenWeb("subsite"))

                {                    

                    results = web.GetSiteData(q);

                }

            }

    To achieve this using web service, you may consider customizing your web service to execute the query, here is an article about this, please refer to it for more information:
    http://msdn.microsoft.com/en-us/library/ms464040.aspx

    Thanks,
    Qiao


    Qiao Wei

    TechNet Community Support

    • Marked as answer by Qiao Wei Thursday, January 12, 2012 9:19 AM
    Friday, January 6, 2012 5:41 AM

All replies

  • Hi KRIS_Dev,

    To get list items based on a content type under a site collection, you can use SPSiteDataQuery class, it represents a query that can be performed across multiple lists in multiple web sites in the same web site collection, to execute the query, you need to pass the SPSiteDataQuery object to the GetSiteData(SPSiteDataQuery) method, here is the document for SPSiteDataQuery class:
    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsitedataquery.aspx

    You can use the code snippet below to retrieve items form the default ‘Tasks’ or ‘Workflow Tasks’ lists with in a sub site:
    SPSiteDataQuery q = new SPSiteDataQuery();

            q.ViewFields = "<FieldRef Name='Title'/><FieldRef Name='Priority'/><FieldRef Name='Status'/>";

            q.Webs = "<Webs Scope='SiteCollection' />";

            q.Lists = "<Lists BaseType='0' />";

            q.Query = "<Where><Gt><FieldRef Name='ID' /><Value Type='Number'>0</Value></Gt></Where>";

            DataTable results = new DataTable();

            using (SPSite site = new SPSite("http://sharepoint"))

            {

                using (SPWeb web = site.OpenWeb("subsite"))

                {                    

                    results = web.GetSiteData(q);

                }

            }

    To achieve this using web service, you may consider customizing your web service to execute the query, here is an article about this, please refer to it for more information:
    http://msdn.microsoft.com/en-us/library/ms464040.aspx

    Thanks,
    Qiao


    Qiao Wei

    TechNet Community Support

    • Marked as answer by Qiao Wei Thursday, January 12, 2012 9:19 AM
    Friday, January 6, 2012 5:41 AM
  • Hi Qiao Wei,

     

    Thanks for Quick response. Code you mentioned is using object model but my requirement is to use only Sharepoint online webservices which should work for office365.

     

    Please let me know how can we achieve same thing using web services.

     

    Thanks.

    Friday, January 6, 2012 7:49 AM
  • Hi KRIS_Dev,

    Thanks for posting back.

    There is a forum for SharePoint Online, people in that forum are professional about this topic, you can go to that forum for more information.
    Microsoft Online SharePoint Online forum: http://social.technet.microsoft.com/Forums/en/onlineservicessharepoint/threads

    Thanks,
    Qiao


    Qiao Wei

    TechNet Community Support

    Friday, January 6, 2012 10:59 AM