Beispiel #1
0
 /// <summary>
 /// Add ContentType in Library
 /// </summary>
 /// <param name="list"></param>
 /// <param name="contentType"></param>
 /// <returns></returns>
 public static bool AddContentTypeLibrary(this SPList list, string contentType)
 {
     try
     {
         var listSharePoint = new ListSharePoint(list.ParentWeb, Logger, list.Title);
         if (listSharePoint.ExistContentType("Item"))
         {
             listSharePoint.DeleteContentType("Item");
         }
         if (listSharePoint.ExistContentType("Document"))
         {
             listSharePoint.DeleteContentType("Document");
         }
         if (listSharePoint.ExistContentType("Element"))
         {
             listSharePoint.DeleteContentType("Element");
         }
         return(!listSharePoint.ExistContentType(contentType) && listSharePoint.AddContentType(contentType));
     }
     catch (Exception exception)
     {
         Logger.Error(string.Concat("Error AddContentTypeLibrary", exception.Message));
         return(false);
     }
 }
        public void CreateListAddField()
        {
            if (!ContextSharePoint.VerifyServer(Site))
            {
                Assert.Inconclusive();
            }
            var contentType = new ContentType(Site.RootWeb, this.Logger, "TESTHELLO", "TEST", "Elemento");

            contentType.Create(string.Empty);
            ListSharePoint = new ListSharePoint(Site.RootWeb, Logger, "LISTATEST");
            Assert.IsTrue(ListSharePoint.Create("descripcion", ListTemplateType.Contacts, true));
            var siteColumn = new Entities.Artefacts.SiteColumn(new ParamsSiteColumnBaseExtended
            {
                AddPrefix  = false,
                FieldType  = SPFieldType.Text,
                Group      = "Lista",
                Logger     = this.Logger,
                MultiValue = false,
                Name       = "Field1",
                Requiered  = true,
                Web        = Site.RootWeb
            });

            Assert.IsTrue(ListSharePoint.AddField(siteColumn));
            Assert.IsTrue(ListSharePoint.DeleteField(siteColumn));
            Assert.IsTrue(ListSharePoint.Delete());
        }
 public void CreateList()
 {
     if (!ContextSharePoint.VerifyServer(Site))
     {
         Assert.Inconclusive();
     }
     ListSharePoint = new ListSharePoint(Site.RootWeb, Logger, "LISTATEST");
     Assert.IsTrue(ListSharePoint.Create("descripcion", ListTemplateType.Contacts, true));
     Assert.IsTrue(ListSharePoint.Delete());
 }
Beispiel #4
0
 /// <summary>
 /// Add permissions to the library
 /// </summary>
 /// <param name="list"></param>
 /// <param name="group"></param>
 /// <param name="role"></param>
 /// <returns></returns>
 public static bool AddPermisionLibrary(this SPList list, string group, RoleType role)
 {
     try
     {
         var listSharePoint = new ListSharePoint(list.ParentWeb, Logger, list.Title);
         return(listSharePoint.AddPermissionsGroup(group, role));
     }
     catch (Exception exception)
     {
         Logger.Error(string.Concat("Error AddPermisionLibrary:", exception.Message));
         return(false);
     }
 }
        public void CreateListAddContentType()
        {
            if (!ContextSharePoint.VerifyServer(Site))
            {
                Assert.Inconclusive();
            }
            var contentType = new ContentType(Site.RootWeb, this.Logger, "TESTHELLO", "TEST", "Elemento");

            contentType.Create(string.Empty);
            ListSharePoint = new ListSharePoint(Site.RootWeb, Logger, "LISTATEST");
            Assert.IsTrue(ListSharePoint.Create("descripcion", ListTemplateType.Contacts, true));
            Assert.IsTrue(ListSharePoint.AddContentType("TESTHELLO"));
            Assert.IsTrue(ListSharePoint.DeleteContentType("TESTHELLO"));
            Assert.IsFalse(ListSharePoint.AddContentType("TESTBYE"));
            Assert.IsTrue(ListSharePoint.Delete());
        }
Beispiel #6
0
        /// <summary>
        /// Create List
        /// </summary>
        /// <param name="web"></param>
        /// <param name="title"></param>
        /// <param name="description"></param>
        /// <param name="typeList"></param>
        /// <param name="versionControl"></param>
        /// <param name="genericClass"></param>
        /// <returns></returns>
        public static bool CreateList(this SPWeb web, string title, string description, TypeList typeList,
                                      bool versionControl, Type genericClass)
        {
            try
            {
                var list = new ListSharePoint(web, Logger, title);
                ListTemplateType type;
                switch (typeList)
                {
                case TypeList.DocumentLibrary:
                    type = ListTemplateType.DocumentLibrary;
                    break;

                case TypeList.PictureLibrary:
                    type = ListTemplateType.PictureLibrary;
                    break;

                case TypeList.CalendarList:
                    type = ListTemplateType.Events;
                    break;

                default:
                    type = ListTemplateType.GenericList;
                    break;
                }
                var result = list.Create(description, type, versionControl);
                if (genericClass != null)
                {
                    AddFieldInList(list, genericClass);
                }

                return(result);
            }
            catch (Exception exception)
            {
                Logger.Error(string.Concat("Error Create List:", exception.Message));
                return(false);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Add Field in List
        /// </summary>
        /// <param name="list"></param>
        /// <param name="genericClass"></param>
        private static void AddFieldInList(ListSharePoint list, Type genericClass)
        {
            var props = genericClass.GetProperties();

            foreach (var prop in props)
            {
                var fieldType    = "Text";
                var create       = true;
                var choice       = new StringCollection();
                var term         = string.Empty;
                var displayName  = string.Empty;
                var hidden       = false;
                var multiValue   = false;
                var required     = false;
                var group        = Constants.Prefix;
                var defaultValue = string.Empty;
                var addPrefix    = true;

                foreach (
                    var enmarcha in
                    prop.GetCustomAttributes(true).Select(attribute => attribute as EnmarchaAttribute))
                {
                    fieldType   = enmarcha.Type.ToString();
                    create      = enmarcha.Create;
                    term        = enmarcha.Term;
                    multiValue  = enmarcha.MultiValue;
                    displayName = enmarcha.DisplayName;
                    hidden      = enmarcha.Hidden;
                    required    = enmarcha.Required;
                    try
                    {
                        group        = enmarcha.Group;
                        addPrefix    = enmarcha.AddPrefeix;
                        defaultValue = enmarcha.ValueDefault;
                    }

                    catch (Exception exception)
                    {
                        Logger.Error(string.Concat("ENMARCHA Error :", exception.Message));
                    }

                    try
                    {
                        if (enmarcha.Choice != null)
                        {
                            choice.AddRange(enmarcha.Choice);
                        }
                    }
                    catch (Exception exception)
                    {
                        Logger.Error(string.Concat("Error :", exception.Message));
                    }
                }

                if (!create)
                {
                    continue;
                }
                CreateColumnInList(new ParamsColumnSite
                {
                    List         = list,
                    Name         = prop.Name,
                    FieldType    = fieldType,
                    Requiered    = required,
                    DefaultValue = defaultValue,
                    Choice       = choice,
                    Group        = group,
                    MultiValue   = multiValue,
                    AddPrefix    = addPrefix,
                    DisplayName  = displayName
                });
            }
        }