static void CreateWingtipSiteColumns()
        {
            Console.WriteLine();

            fieldProductCode = CreateSiteColumn("ProductCode", "Product Code", "Text");
            fieldProductCode.EnforceUniqueValues = true;
            fieldProductCode.Indexed             = true;
            fieldProductCode.Required            = true;
            fieldProductCode.Update();
            clientContext.ExecuteQuery();
            clientContext.Load(fieldProductCode);
            clientContext.ExecuteQuery();

            fieldProductDescription = clientContext.CastTo <FieldMultiLineText>(CreateSiteColumn("ProductDescription", "Product Description", "Note"));
            fieldProductDescription.NumberOfLines = 4;
            fieldProductDescription.RichText      = false;
            fieldProductDescription.Update();
            clientContext.ExecuteQuery();

            fieldProductListPrice = clientContext.CastTo <FieldCurrency>(CreateSiteColumn("ProductListPrice", "List Price", "Currency"));
            fieldProductListPrice.MinimumValue = 0;
            fieldProductListPrice.Update();
            clientContext.ExecuteQuery();

            fieldProductColor = clientContext.CastTo <FieldMultiChoice>(CreateSiteColumn("ProductColor", "Product Color", "MultiChoice"));
            string[] choicesProductColor = { "White", "Black", "Grey", "Blue", "Red", "Green", "Yellow" };
            fieldProductColor.Choices = choicesProductColor;
            fieldProductColor.Update();
            clientContext.ExecuteQuery();

            fieldMinimumAge = clientContext.CastTo <FieldNumber>(CreateSiteColumn("MinimumAge", "Minimum Age", "Number"));
            fieldMinimumAge.MinimumValue = 1;
            fieldMinimumAge.MaximumValue = 100;
            fieldMinimumAge.Update();
            clientContext.ExecuteQuery();

            fieldMaximumAge = clientContext.CastTo <FieldNumber>(CreateSiteColumn("MaximumAge", "Maximum Age", "Number"));
            fieldMaximumAge.MinimumValue = 1;
            fieldMaximumAge.MaximumValue = 100;
            fieldMaximumAge.Update();
            clientContext.ExecuteQuery();

            fieldProductImageUrl = clientContext.CastTo <FieldUrl>(CreateSiteColumn("ProductImageUrl", "Product Image Url", "URL"));
            fieldProductImageUrl.DisplayFormat = UrlFieldFormatType.Image;
            fieldProductImageUrl.Update();
            clientContext.ExecuteQuery();
        }
Exemplo n.º 2
0
 public FieldMultiChoiceInformation(FieldMultiChoice field) : base(field)
 {
     Choices      = field.Choices;
     FillInChoice = field.FillInChoice;
     Mappings     = field.Mappings;
 }
        static void CreateWingtipSiteColumns()
        {
            Console.WriteLine();

              fieldProductCode = CreateSiteColumn("ProductCode", "Product Code", "Text");
              fieldProductCode.EnforceUniqueValues = true;
              fieldProductCode.Indexed = true;
              fieldProductCode.Required = true;
              fieldProductCode.Update();
              clientContext.ExecuteQuery();
              clientContext.Load(fieldProductCode);
              clientContext.ExecuteQuery();

              fieldProductDescription = clientContext.CastTo<FieldMultiLineText>(CreateSiteColumn("ProductDescription", "Product Description", "Note"));
              fieldProductDescription.NumberOfLines = 4;
              fieldProductDescription.RichText = false;
              fieldProductDescription.Update();
              clientContext.ExecuteQuery();

              fieldProductListPrice = clientContext.CastTo<FieldCurrency>(CreateSiteColumn("ProductListPrice", "List Price", "Currency"));
              fieldProductListPrice.MinimumValue = 0;
              fieldProductListPrice.Update();
              clientContext.ExecuteQuery();

              fieldProductCategory = clientContext.CastTo<TaxonomyField>(CreateSiteColumn("ProductCategory", "Product Category", "TaxonomyFieldType"));
              fieldProductCategory.SspId = localTermStoreID;
              fieldProductCategory.TermSetId = termSetId;
              fieldProductCategory.AllowMultipleValues = false;
              fieldProductCategory.Update();
              clientContext.ExecuteQuery();

              fieldProductColor = clientContext.CastTo<FieldMultiChoice>(CreateSiteColumn("ProductColor", "Product Color", "MultiChoice"));
              string[] choicesProductColor = { "White", "Black", "Grey", "Blue", "Red", "Green", "Yellow" };
              fieldProductColor.Choices = choicesProductColor;
              fieldProductColor.Update();
              clientContext.ExecuteQuery();

              fieldMinimumAge = clientContext.CastTo<FieldNumber>(CreateSiteColumn("MinimumAge", "Minimum Age", "Number"));
              fieldMinimumAge.MinimumValue = 1;
              fieldMinimumAge.MaximumValue = 100;
              fieldMinimumAge.Update();
              clientContext.ExecuteQuery();

              fieldMaximumAge = clientContext.CastTo<FieldNumber>(CreateSiteColumn("MaximumAge", "Maximum Age", "Number"));
              fieldMaximumAge.MinimumValue = 1;
              fieldMaximumAge.MaximumValue = 100;
              fieldMaximumAge.Update();
              clientContext.ExecuteQuery();

              fieldProductImageUrl = clientContext.CastTo<FieldUrl>(CreateSiteColumn("ProductImageUrl", "Product Image Url", "URL"));
              fieldProductImageUrl.DisplayFormat = UrlFieldFormatType.Image;
              fieldProductImageUrl.Update();
              clientContext.ExecuteQuery();
        }
Exemplo n.º 4
0
        static void CreateWingtipSiteColumns()
        {
            Console.WriteLine();

              fieldProductCode = CreateSiteColumn("ProductCode", "Product Code", "Text");
              fieldProductCode.EnforceUniqueValues = true;
              fieldProductCode.Indexed = true;
              fieldProductCode.Required = true;
              fieldProductCode.Update();
              clientContext.ExecuteQuery();
              clientContext.Load(fieldProductCode);
              clientContext.ExecuteQuery();

              fieldProductDescription = clientContext.CastTo<FieldMultiLineText>(CreateSiteColumn("ProductDescription", "Product Description", "Note"));
              fieldProductDescription.NumberOfLines = 4;
              fieldProductDescription.RichText = false;
              fieldProductDescription.Update();
              clientContext.ExecuteQuery();

              fieldProductListPrice = clientContext.CastTo<FieldCurrency>(CreateSiteColumn("ProductListPrice", "Product List Price", "Currency"));
              fieldProductListPrice.MinimumValue = 0;
              fieldProductListPrice.Update();
              clientContext.ExecuteQuery();

              fieldProductColor = clientContext.CastTo<FieldMultiChoice>(CreateSiteColumn("ProductColor", "Product Color", "MultiChoice"));
              string[] choicesProductColor = { "White", "Black", "Grey", "Blue", "Red", "Green", "Yellow" };
              fieldProductColor.Choices = choicesProductColor;
              fieldProductColor.Update();
              clientContext.ExecuteQuery();

              fieldMinimumAge = clientContext.CastTo<FieldNumber>(CreateSiteColumn("MinimumAge", "Minimum Age", "Number"));
              fieldMinimumAge.MinimumValue = 1;
              fieldMinimumAge.MaximumValue = 100;
              fieldMinimumAge.Update();
              clientContext.ExecuteQuery();

              fieldMaximumAge = clientContext.CastTo<FieldNumber>(CreateSiteColumn("MaximumAge", "Maximum Age", "Number"));
              fieldMaximumAge.MinimumValue = 1;
              fieldMaximumAge.MaximumValue = 100;
              fieldMaximumAge.Update();
              clientContext.ExecuteQuery();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Lanza el proceso de creación de nuevas columnas
        /// </summary>
        /// <returns></returns>
        public bool CreateColumns()
        {
            bool result          = true;
            List list            = null;
            bool continueProcess = true;

            if (ConectionSiteOK)
            {
                if (SPFields.Count > 0)
                {
                    foreach (SPFields infoField in SPFields)
                    {
                        continueProcess = true;
                        try
                        {
                            list = site.Web.Lists.GetByTitle(infoField.ListName);
                        }
                        catch (Exception ex)
                        {
                            SHPExecOperationsErrors.Add(GetInfoError(ex, string.Format("Alta de nuevo campo {0}", infoField.ColumnName), TypeError.Error));
                            continueProcess = false;
                        }

                        if (continueProcess)
                        {
                            //Configuramos...
                            switch (infoField.Column)
                            {
                            case TypeColumn.LineOfText:
                                //Linea de texto
                                Field newField1 = list.Fields.AddFieldAsXml(string.Format(schemaXML, infoField.Type, infoField.ColumnName), true, AddFieldOptions.AddToDefaultContentType);
                                newField1.StaticName  = infoField.ColumnName;
                                newField1.Description = infoField.Description;

                                if (infoField.FieldText != null)
                                {
                                    FieldText fldText = site.CastTo <FieldText>(newField1);
                                    fldText.Required            = infoField.FieldText.ContainInformation;
                                    fldText.EnforceUniqueValues = infoField.FieldText.UniqueValues;
                                    fldText.MaxLength           = infoField.FieldText.MaxLength;
                                    fldText.DefaultValue        = infoField.FieldText.DefaultValue;
                                    if (infoField.FieldText.UniqueValues)
                                    {
                                        fldText.Indexed = true;
                                    }
                                    fldText.Update();
                                }
                                else
                                {
                                    continueProcess = false;
                                }
                                break;

                            case TypeColumn.Multiline:
                                //Varias líneas de texto
                                Field newField2 = list.Fields.AddFieldAsXml(string.Format(schemaXML, infoField.Type, infoField.ColumnName), true, AddFieldOptions.AddToDefaultContentType);
                                newField2.StaticName  = infoField.ColumnName;
                                newField2.Description = infoField.Description;

                                if (infoField.FieldMultiText != null)
                                {
                                    FieldMultiLineText fldMultiLine = site.CastTo <FieldMultiLineText>(newField2);
                                    fldMultiLine.Required      = infoField.FieldMultiText.ContainInformation;
                                    fldMultiLine.NumberOfLines = infoField.FieldMultiText.NumLines;
                                    fldMultiLine.RichText      = infoField.FieldMultiText.RichText;
                                    fldMultiLine.Update();
                                }
                                else
                                {
                                    continueProcess = false;
                                }
                                break;

                            case TypeColumn.Choice:
                                //Eleccion
                                Field newField3 = list.Fields.AddFieldAsXml(string.Format(schemaXML, infoField.Type, infoField.ColumnName), true, AddFieldOptions.AddToDefaultContentType);
                                newField3.StaticName  = infoField.ColumnName;
                                newField3.Description = infoField.Description;

                                if (infoField.FieldChoice != null)
                                {
                                    FieldMultiChoice fldChoice = site.CastTo <FieldMultiChoice>(newField3);
                                    fldChoice.Required            = infoField.FieldChoice.ContainInformation;
                                    fldChoice.EnforceUniqueValues = infoField.FieldChoice.UniqueValues;
                                    fldChoice.DefaultValue        = infoField.FieldChoice.DefaultValue;
                                    if (infoField.FieldChoice.UniqueValues)
                                    {
                                        fldChoice.Indexed = true;
                                    }
                                    fldChoice.Choices = infoField.FieldChoice.Options;
                                    fldChoice.Update();
                                }
                                else
                                {
                                    continueProcess = false;
                                }
                                break;

                            case TypeColumn.Number:
                                //Numero
                                Field newField4 = list.Fields.AddFieldAsXml(string.Format(schemaXML, infoField.Type, infoField.ColumnName), true, AddFieldOptions.AddToDefaultContentType);
                                newField4.StaticName  = infoField.ColumnName;
                                newField4.Description = infoField.Description;

                                if (infoField.FieldNumber != null)
                                {
                                    FieldNumber fldNumber = site.CastTo <FieldNumber>(newField4);
                                    fldNumber.ShowAsPercentage = infoField.FieldNumber.ShowAsPercentaje;
                                    if (infoField.FieldNumber.MinValue != 0)
                                    {
                                        fldNumber.MinimumValue = infoField.FieldNumber.MinValue;
                                    }
                                    if (infoField.FieldNumber.MaxValue != 0)
                                    {
                                        fldNumber.MaximumValue = infoField.FieldNumber.MaxValue;
                                    }

                                    fldNumber.Update();
                                }
                                else
                                {
                                    continueProcess = false;
                                }
                                break;

                            case TypeColumn.Lookup:
                                if (infoField.FieldLookup != null)
                                {
                                    string required = "FALSE";
                                    if (infoField.FieldLookup.ContainInformation)
                                    {
                                        required = "TRUE";
                                    }

                                    try
                                    {
                                        List sourceList = site.Web.Lists.GetByTitle(infoField.FieldLookup.LookupList);
                                        site.Load(sourceList);

                                        List destinationList = site.Web.Lists.GetByTitle(infoField.ListName);
                                        site.Load(destinationList);

                                        site.ExecuteQuery();

                                        Field LookUpField = destinationList.Fields.AddFieldAsXml(string.Format(schemaXMLLookUp, infoField.Type, infoField.ColumnName, required, sourceList.Id, infoField.FieldLookup.LookupField), true, AddFieldOptions.DefaultValue);
                                        LookUpField.Description = infoField.Description;
                                        LookUpField.Update();
                                    }
                                    catch (Exception ex)
                                    {
                                        SHPExecOperationsErrors.Add(GetInfoError(ex, string.Format("Alta de nuevo campo {0}", infoField.ColumnName), TypeError.Error));
                                        continueProcess = false;
                                    }
                                }
                                else
                                {
                                    continueProcess = false;
                                }
                                break;

                            case TypeColumn.UsersAndGroups:
                                Field newField5 = list.Fields.AddFieldAsXml(string.Format(schemaXML, infoField.Type, infoField.ColumnName), true, AddFieldOptions.AddToDefaultContentType);
                                newField5.StaticName  = infoField.ColumnName;
                                newField5.Description = infoField.Description;

                                if (infoField.FieldUserGroup != null)
                                {
                                    FieldUser fldUser = site.CastTo <FieldUser>(newField5);
                                    fldUser.Required = infoField.FieldUserGroup.ContainInformation;
                                    switch (infoField.FieldUserGroup.UserSelectionMode)
                                    {
                                    case TypeUserSelectionMode.PeopleOnly:
                                        fldUser.SelectionMode = FieldUserSelectionMode.PeopleOnly;
                                        break;

                                    case TypeUserSelectionMode.PeopleAndGroups:
                                        fldUser.SelectionMode = FieldUserSelectionMode.PeopleAndGroups;
                                        break;
                                    }

                                    if (infoField.FieldUserGroup.MultiUser)
                                    {
                                        fldUser.AllowMultipleValues = true;
                                    }

                                    if (!string.IsNullOrEmpty(infoField.FieldUserGroup.UsersFromGroup))
                                    {
                                        Group group = site.Web.SiteGroups.GetByName(infoField.FieldUserGroup.UsersFromGroup);

                                        try
                                        {
                                            site.Load(group);
                                            site.ExecuteQuery();
                                        }
                                        catch (Exception ex)
                                        {
                                            SHPExecOperationsErrors.Add(GetInfoError(ex, string.Format("Alta de nuevo campo {0}", infoField.ColumnName), TypeError.Warning));
                                            group = null;
                                        }

                                        if (group != null)
                                        {
                                            fldUser.SelectionGroup = group.Id;
                                        }
                                    }

                                    fldUser.Update();
                                }
                                else
                                {
                                    continueProcess = false;
                                }

                                break;
                            }

                            //Añadimos...
                            if (continueProcess)
                            {
                                try
                                {
                                    site.ExecuteQuery();
                                }
                                catch (Exception ex)
                                {
                                    SHPExecOperationsErrors.Add(GetInfoError(ex, string.Format("Alta de nuevo campo {0}", infoField.ColumnName), TypeError.Error));
                                }
                            }
                        }

                        list = null;
                    }
                }
                else
                {
                    SHPExecOperationsErrors.Add(GetInfoError("Creación de columnas (CreateColumns)", "No se han indicado campos a crear", "", TypeError.Warning));
                    result = false;
                }
            }
            else
            {
                SHPExecOperationsErrors.Add(GetInfoError("Creación de columnas (CreateColumns)", "No se ha establecido conexión con el site", "", TypeError.Warning));
                result = false;
            }

            SPFields.Clear();

            return(result);
        }