示例#1
0
        private void cmd_Get_Fields_Click(object sender, EventArgs e)
        {
            // Store selected row
            int row = dgv_Data.SelectedCells[0].RowIndex;

            // Store column of List Name
            int col = dgv_Data.Columns["listName"].Index;

            // Store site List Name
            string listName = dgv_Data[col, row].Value.ToString();

            // Store column of Site Address
            col = dgv_Data.Columns["siteAddress"].Index;

            // Store column of Site Address
            string siteAddress = dgv_Data[col, row].Value.ToString();

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

            // Store site URL if it exists
            string siteUrl = null;

            // Store site URL
            if (dgv_Data[col, row].Value != null)
            {
                siteUrl = dgv_Data[col, row].Value.ToString();
            }
            else
            {
                siteUrl = siteAddress;
            }

            // Open the List form
            frm_Data_Field fieldForm = OpenForm_Field(listName, this.Name, this.lbl_Header.Tag.ToString(), siteUrl);

            // Store column of GUID
            col = dgv_Data.Columns["listId"].Index;

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

            // Add records to the data grid
            AddFields(fieldForm, listId, siteAddress);

            // Show the List form
            fieldForm.Show();
        }
示例#2
0
        public frm_Data_Field OpenForm_Field(string listName, string tag, string subSiteName, string siteUrl)
        {
            // Create a new instance of the Site class
            frm_Data_Field fieldForm = new frm_Data_Field();

            fieldForm.Height      = 700;
            fieldForm.Width       = 1500;
            fieldForm.WindowState = FormWindowState.Maximized;

            fieldForm.Text            = siteUrl;
            fieldForm.lbl_Header.Text = "Fields - " + listName + " (" + subSiteName + ")";
            fieldForm.Tag             = tag;

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

            return(fieldForm);
        }
示例#3
0
        private void AddFields(frm_Data_Field fieldForm, string listId, string siteAddress)
        {
            Guid g = new Guid(listId);

            SP.ClientContext clientContext = SharePoint.GetClient(siteAddress, frm_Main_Menu.username, frm_Main_Menu.password);
            SP.List          oList         = clientContext.Web.Lists.GetById(g);

            // Load in the Fields
            clientContext.Load(oList.Fields);
            clientContext.ExecuteQuery();

            int i = 0;

            foreach (SP.Field oField in oList.Fields)
            {
                // Store the Field Type
                string fieldType = oField.TypeAsString;

                // We will exclude some entries by Field Type
                bool skip = false;

                // These 2 attributes will depend on the field type
                string maxLength = null;
                string formula   = null;

                // Find field types for specific actions
                switch (fieldType)
                {
                // Max Length
                case "Text":

                    // Convert to "Text Field"
                    SP.FieldText textField = (SP.FieldText)oField;

                    // We now have access to the attribute
                    maxLength = textField.MaxLength.ToString();

                    // Break out of the switch
                    break;

                // Formula
                case "Calculated":

                    // Convert to "Calculated Field"
                    FieldCalculated calcField = (FieldCalculated)oField;

                    // We now have access to the attribute
                    formula = calcField.Formula;

                    // Break out of the switch
                    break;

                // We won't include "Computed" or "Lookup" fields
                case "Lookup":
                case "Computed":

                    // Skip
                    skip = true;

                    // Break out of the switch
                    break;
                }

                if (skip == false)
                //if (true)
                {
                    i++;

                    string fieldName           = oField.Title;
                    string defaultValue        = oField.DefaultValue;
                    string enforceUniqueValues = oField.EnforceUniqueValues.ToString();
                    string required            = oField.Required.ToString();
                    string readOnly            = oField.ReadOnlyField.ToString();
                    string isSealed            = oField.Sealed.ToString();

                    fieldForm.AddRow
                    (
                        i,
                        fieldName,
                        oField.InternalName,
                        fieldType,
                        maxLength,
                        enforceUniqueValues,
                        required,
                        readOnly,
                        isSealed,
                        defaultValue,
                        formula
                    );

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