Beispiel #1
0
        public frm_Data_Site OpenForm()
        {
            // Create a new instance of the Site class
            frm_Data_Site siteForm = new frm_Data_Site();

            // Give a new header row
            siteForm.Text            = "Sites";
            siteForm.lbl_Header.Text = "Sites && Sub-Sites";

            // Re-size the form
            siteForm.Height      = 700;
            siteForm.Width       = 1000;
            siteForm.WindowState = FormWindowState.Maximized;

            // Add columns to the data grid view
            siteForm.AddColumns();

            // Return the form object
            return(siteForm);
        }
Beispiel #2
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);
        }
Beispiel #3
0
        private void cmd_Get_Sites_Click(object sender, EventArgs e)
        {
            // Set the public variables
            SetStaticVars();

            // Try to get the client
            ClientContext clientContext = GetClient();

            // Exit if we got an error
            if (clientContext == null)
            {
                return;
            }

            // Open the Site form
            frm_Data_Site siteForm = OpenForm();

            // Output all the sites/sub-sites into the data grid view
            GetSiteAndSubSites(clientContext, siteForm, chk_Recursive.Checked);

            // Show the Site form
            siteForm.ShowDialog();
        }
Beispiel #4
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);
                    }
                }
            }
        }