2

I am trying to get the tasks list of all my SPWebs in my site collection using spsitequery , but I am getting dt.rows.count =0.That means

No Records found

though I have added 2 records - ie, I am having 2 sub sites[publishing] namely project1, project2 with task lists with1 record.

here is my code:

       static void Main(string[] args)
    {

        DataTable dtResults =null;
        DataTable dtDistinctResults =null;

        try
        {

    using (SPSite OOSITE=  new SPSite("http://mysitecol-
           01:2016/sites/EMD/"))
        {
         using(SPWeb objweb = OOSITE.OpenWeb())
          //using(SPWeb objweb = OOSITE.RootWeb)
         {

             SPSiteDataQuery dataQuery = new SPSiteDataQuery();
             dataQuery.Webs = "<Webs Scope=\"SiteCollection\" />";
             dataQuery.Lists = "<Lists ServerTemplate=\"107\" />";
             dataQuery.ViewFields = "<FieldRef Name=\"AssignedTo\"/>" + "
            <FieldRef Name=\"Task Name\" />" + "<FieldRef 
            Name=\"Description\" />"; // +"<FieldRef Name=\"FileRef\" 
              />";
             string where = "";

            dataQuery.Query = "<OrderBy> <FieldRef Name=\"AssignedTo\"/> 
              </OrderBy>";

             DataTable dt = objweb.GetSiteData(dataQuery);

             if (dt.Rows.Count > 0)
             {
                 Console.WriteLine("record exists in site collec-     
                division");
                 DataView dv = new DataView(dt);
             }
             else
              {
                Console.WriteLine("NO RECORDS FOUND in site collec-
               division");
                  Console.ReadLine();
              }
             //gvResult.DataSource = dv;
             //gvResult.DataBind();
        }
            }
        }
        catch (Exception EXPP)
        {
            string loggerr = EXPP.Message + "__" + EXPP.StackTrace;
        }

 am always getting "NO RECORDS FOUND in site collec-division");
What I am doing wrong? 

i tried the code HERE as well.

  • any help, answers , pls.ha anyone faced the same issue before? – SaMolPP Mar 2 '16 at 7:05
  • Did you get to the bottom of this? – Vivek Ayer Aug 23 '16 at 11:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.