示例#1
0
        private void GetSiteAndSubSites(ClientContext clientContext, frm_Data_Site siteForm, bool recursive)
        {
            // Get the SharePoint web
            Web web = clientContext.Web;

            // Load lists
            clientContext.Load(web.Lists);

            // Execute the query to the server
            clientContext.ExecuteQuery();

            // Store the data grid view's row count
            int i = siteForm.dgv_Data.RowCount + 1;

            // Add row to data grid view
            siteForm.AddRow(i.ToString(), web.Title, null, web.Lists.Count.ToString(), web.Created, web.Url);

            // Loop through sub-sites
            GetSubSites(clientContext, web, siteForm, recursive, null);
        }
示例#2
0
        private void GetSubSites(ClientContext clientContext, Web web, frm_Data_Site siteForm, bool recursive, string parent)
        {
            // Load objects
            clientContext.Load(web, website => website.Webs, website => website.Title, website => website.Url);

            // Load lists
            //clientContext.Load(web.Lists);

            // Execute the query to the server
            clientContext.ExecuteQuery();

            // Loop through all the webs
            foreach (Web subWeb in web.Webs)
            {
                // Check whether it is an app URL or not - If not then get into this block
                if (subWeb.Url.Contains(web.Url))
                {
                    // Store the data grid view's row count
                    int i = siteForm.dgv_Data.RowCount + 1;

                    // Check to see if we have exceeded the limit
                    if (siteForm.dgv_Data.RowCount >= nud_Limit.Value && nud_Limit.Value != 0)
                    {
                        return;
                    }

                    // Store full path of parent
                    string parentNew = null;

                    // If the incoming parent variable is null, we are at the top
                    if (parent != null)
                    {
                        // New parent is incoming parent with the (parent) web title
                        parentNew = parent + " --> " + web.Title;
                    }
                    else
                    {
                        // New parent is just the (parent) web title
                        parentNew = web.Title;
                    }

                    // Load lists
                    clientContext.Load(subWeb.Lists);

                    // Execute the query to the server
                    clientContext.ExecuteQuery();

                    // Add row to data grid view
                    siteForm.AddRow(i.ToString(), subWeb.Title, parentNew, subWeb.Lists.Count.ToString(), web.Created, subWeb.Url);

                    this.lbl_Site_Count.Text = i.ToString() + " site(s) found";
                    this.lbl_Site_Count.Refresh();

                    // Loop through sub-sites
                    if (recursive)
                    {
                        GetSubSites(clientContext, subWeb, siteForm, recursive, parentNew);
                    }
                }
            }
        }