Beispiel #1
0
        private void GetAllListsForSelectedSite()
        {
            // Store selected row
            int row = dgv_Data.SelectedCells[0].RowIndex;

            // Store column of URL
            int col = dgv_Data.Columns["url"].Index;

            // Store site URL
            string siteUrl = dgv_Data[col, row].Value.ToString();

            // Store column of Site Name
            col = dgv_Data.Columns["parent"].Index;

            // Create a variable for the Site Name
            string siteName = "";

            // Store parent site name if we are not at the top level
            if (dgv_Data[col, row].Value != null)
            {
                siteName = dgv_Data[col, row].Value.ToString() + " --> ";
            }

            // Store column of Site Name
            col = dgv_Data.Columns["siteName"].Index;

            // Store site name
            siteName += dgv_Data[col, row].Value.ToString();

            // Open the List form
            frm_Data_List listForm = OpenForm(siteName, siteUrl, this.Name, 1500, 700);

            // Hide the Site Name column
            listForm.dgv_Data.Columns["siteName"].Visible = false;

            // Hide the Site Name column
            listForm.dgv_Data.Columns["siteAddress"].Visible = false;

            // Get lists
            AddLists(siteName, siteUrl, listForm);

            // Show the List form
            listForm.Show();
        }
Beispiel #2
0
        public frm_Data_List OpenForm(string siteName, string siteUrl, string tag, int width, int height)
        {
            // Create a new instance of the Site class
            frm_Data_List listForm = new frm_Data_List();

            listForm.Width       = width;
            listForm.Height      = height;
            listForm.WindowState = FormWindowState.Maximized;

            listForm.Text            = siteUrl;
            listForm.lbl_Header.Text = "Lists - " + siteName;
            listForm.lbl_Header.Tag  = siteName;
            listForm.Tag             = tag;

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

            return(listForm);
        }
Beispiel #3
0
        private void GetListByNameOrGuid(string listGuid, string listName)
        {
            txt_Guid.Text = "";
            txt_Name.Text = "";

            // Store loop counter for rows added to the data grid view
            int i = 0;

            // If we find a GUID, there will only be one
            bool foundGuid = false;

            // Store variables for field values
            string defaultViewUrl   = null;
            string defaultViewTitle = null;
            string viewCount        = null;
            string fieldCount       = null;
            string itemCount        = null;
            string listType         = null;
            string siteName         = null;
            string siteAddress      = null;
            string listTitle        = null;

            // Open the List form
            frm_Data_List listForm = OpenForm("", "", this.Name, 1000, 500);

            // Show the Site Name column
            listForm.dgv_Data.Columns["siteName"].Visible = true;

            // Hide the Site Address column
            listForm.dgv_Data.Columns["siteAddress"].Visible = false;

            // Loop through each row of the data grid view
            foreach (DataGridViewRow row in dgv_Data.Rows)
            {
                // If we find a GUID, there will only be one
                foundGuid = false;

                // Store the Site URL to get the Client Context
                string siteUrl = row.Cells[5].Value.ToString();

                // Select the row in the data grid view for visual effect
                row.Selected = true;

                // Do this or it won't show the selected record
                dgv_Data.Refresh();

                // Get the Client Context
                ClientContext clientContext = SharePoint.GetClient(siteUrl, frm_Main_Menu.username, frm_Main_Menu.password);

                // Store the lists
                ListCollection collList = clientContext.Web.Lists;

                // Load lists
                clientContext.Load(collList);

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

                // Loop through each list to check against Name (i.e. Title) or GUID
                foreach (SP.List oList in collList)
                {
                    // Variable to check if we need to add a row
                    bool addRow = false;

                    // If we have a GUID, check the GUID
                    if (listGuid != "")
                    {
                        // Check the GUID
                        if (oList.Id.ToString() == listGuid)
                        {
                            // Select the cell to indicate a find
                            row.Cells[1].Selected = true;

                            // Set the variables
                            foundGuid = true;
                            addRow    = true;
                        }
                    }
                    // We are checking name
                    else
                    {
                        // Do a contains for basic "fuzzy" matching
                        if (oList.Title.ToLower().Contains(listName.ToLower()))
                        {
                            // Select the cell to indicate a find
                            row.Cells[1].Selected = true;

                            // Set the variable to add a row
                            addRow = true;
                        }
                    }

                    // Check if we are needing to add a row to the data grid view
                    if (addRow)
                    {
                        // Increment counter
                        i++;

                        // Load lists
                        clientContext.Load(oList, l => l.SchemaXml);

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

                        // Set the field-related vairables
                        SetFieldVars(clientContext, oList, listForm.dgv_Data, ref fieldCount);

                        // Set the view-related variables
                        SetViewVars(clientContext, oList, listForm.dgv_Data, ref defaultViewUrl, ref defaultViewTitle, ref viewCount);

                        // Set other variables
                        itemCount   = oList.ItemCount.ToString();
                        listType    = GetBaseTypeDescription(oList.BaseType);
                        siteAddress = row.Cells[5].Value.ToString();
                        listTitle   = oList.Title;

                        // Find the full Site Name that the List belongs to
                        if (row.Cells[2].Value != null)
                        {
                            siteName = row.Cells[2].Value.ToString() + " --> " + row.Cells[1].Value.ToString();
                        }
                        else
                        {
                            siteName = row.Cells[1].Value.ToString();
                        }

                        // Add a row to the data grid view
                        listForm.AddRow
                        (
                            i.ToString(),
                            siteName,
                            siteAddress,
                            listTitle,
                            oList.Description,
                            listType,
                            oList.EnableVersioning,
                            oList.MajorVersionLimit,
                            defaultViewTitle,
                            fieldCount,
                            viewCount,
                            itemCount,
                            !oList.DisableGridEditing,
                            oList.Id.ToString(),
                            oList.Created.ToString(),
                            defaultViewUrl,
                            oList.SchemaXml.ToString()
                        );

                        lbl_Row_Count.Text = i.ToString() + " record(s) found";
                        lbl_Row_Count.Refresh();

                        // Show the form if it is still invisible
                        if (listForm.Visible == false)
                        {
                            listForm.Show();
                        }

                        // Refresh it for visual effects
                        listForm.Refresh();

                        // Leave if the addition was the result of a GUID match
                        if (foundGuid == true)
                        {
                            break;
                        }
                    }
                }

                // Leave if the addition was the result of a GUID match
                if (foundGuid == true)
                {
                    break;
                }
            }

            if (i > 0)
            {
                if (foundGuid == true)
                {
                    MessageBox.Show("Found list '" + listTitle + "' with GUID " + listGuid);
                }
                else
                {
                    MessageBox.Show("Found " + i + " list(s) matching the name '" + listName + "'");
                }
            }
            else
            {
                MessageBox.Show("Could not find a match");
            }
        }
Beispiel #4
0
        private void AddLists(string siteName, string siteUrl, frm_Data_List listForm)
        {
            ClientContext  clientContext = SharePoint.GetClient(siteUrl, frm_Main_Menu.username, frm_Main_Menu.password);
            ListCollection collList      = SharePoint.GetLists(clientContext);

            // Initialise row counter
            int i = 0;

            foreach (SP.List oList in collList)
            {
                // Load lists
                clientContext.Load(oList, l => l.SchemaXml);

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

                string defaultViewUrl   = null;
                string defaultViewTitle = null;
                string viewCount        = null;
                string fieldCount       = null;
                string itemCount        = oList.ItemCount.ToString();
                string listType         = GetBaseTypeDescription(oList.BaseType);

                SetFieldVars(clientContext, oList, listForm.dgv_Data, ref fieldCount);
                SetViewVars(clientContext, oList, listForm.dgv_Data, ref defaultViewUrl, ref defaultViewTitle, ref viewCount);

                // Increment counter
                i++;

                //oList.DisableGridEditing = (listType == "List");
                //oList.Update();

                listForm.AddRow
                (
                    i.ToString(),
                    siteName,
                    siteUrl,
                    oList.Title,
                    oList.Description,
                    listType,
                    oList.EnableVersioning,
                    oList.MajorVersionLimit,
                    defaultViewTitle,
                    fieldCount,
                    viewCount,
                    itemCount,
                    !oList.DisableGridEditing,
                    oList.Id.ToString(),
                    oList.Created.ToString(),
                    defaultViewUrl,
                    oList.SchemaXml.ToString()
                );

                lbl_Row_Count.Text = i.ToString() + " record(s) found";
                lbl_Row_Count.Refresh();

                if (i >= nud_Row_Limit.Value && nud_Row_Limit.Value != 0)
                {
                    break;
                }
            }

            //clientContext.ExecuteQuery();
        }