예제 #1
0
        private void cmd_Get_Users_Click(object sender, EventArgs e)
        {
            // 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_User userForm = OpenForm_User(siteName, siteUrl, this.Name, 1500, 700);

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

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

            // Get lists
            AddUsers(siteName, siteUrl, userForm);

            // Show the List form
            userForm.Show();
        }
예제 #2
0
        public frm_Data_User OpenForm_User(string siteName, string siteUrl, string tag, int width, int height)
        {
            // Create a new instance of the Site class
            frm_Data_User userForm = new frm_Data_User();

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

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

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

            return(userForm);
        }
예제 #3
0
        private void AddUsers(string siteName, string siteUrl, frm_Data_User userForm)
        {
            ClientContext clientContext = SharePoint.GetClient(siteUrl, frm_Main_Menu.username, frm_Main_Menu.password);

            Web web = clientContext.Web;

            // Instantiates the User Information List
            SP.List userList = web.SiteUserInfoList;

            // Get the current user
            SP.User user = web.CurrentUser;

            // Initialise row counter
            int rowNum = 0;

            // Create a new Caml Query
            CamlQuery camlQuery = new CamlQuery();

            // Set the XML
            camlQuery.ViewXml = "<View><Query>{0}</Query></View>";

            // Define a collection to store the list items in
            ListItemCollection collListItem = userList.GetItems(camlQuery);


            // Load in the items
            clientContext.Load(collListItem, icol => icol.Include(i => i.ContentType));
            clientContext.Load(collListItem);

            // Attempt to retreive the List Items
            try
            {
                clientContext.ExecuteQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }

            foreach (SP.ListItem oListItem in collListItem)
            {
                // Increment counter
                rowNum++;

                int id = (int)oListItem.FieldValues["ID"];

                object firstName  = oListItem.FieldValues["FirstName"];
                object lastName   = oListItem.FieldValues["LastName"];
                object fullName   = oListItem.FieldValues["Title"];
                object userName   = oListItem.FieldValues["UserName"];
                object email      = oListItem.FieldValues["EMail"];
                object sipAddress = oListItem.FieldValues["SipAddress"];

                object isSiteAdmin = oListItem.FieldValues["IsSiteAdmin"];
                object deleted     = oListItem.FieldValues["Deleted"];
                object hidden      = oListItem.FieldValues["UserInfoHidden"];
                object isActive    = oListItem.FieldValues["IsActive"];

                string ContentTypeName = oListItem.ContentType.Name;
                object guid            = oListItem.FieldValues["GUID"];

                DateTime          createDate = Convert.ToDateTime(oListItem.FieldValues["Created"]);
                SP.FieldUserValue author     = (SP.FieldUserValue)oListItem.FieldValues["Author"];
                string            createUser = author.LookupValue.ToString();

                DateTime          modifyDate = Convert.ToDateTime(oListItem.FieldValues["Modified"]);
                SP.FieldUserValue editor     = (SP.FieldUserValue)oListItem.FieldValues["Editor"];
                string            modifyUser = editor.LookupValue.ToString();

                if (firstName != null)
                {
                    //System.Diagnostics.Debugger.Break();
                }

                userForm.AddRow
                (
                    rowNum,
                    id,
                    firstName,
                    lastName,
                    fullName,
                    userName,
                    email,
                    sipAddress,
                    isSiteAdmin,
                    deleted,
                    hidden,
                    isActive,
                    ContentTypeName,
                    guid,
                    createDate,
                    createUser,
                    modifyDate,
                    modifyUser
                );

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

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