Enmarcha.SharePoint.Entities.Artefacts.ListSharePoint.ExistContentType C# (CSharp) Method

ExistContentType() public method

Existe este Tipo de contenido en la Lista
public ExistContentType ( string contentTypeName ) : bool
contentTypeName string
return bool
        public bool ExistContentType(string contentTypeName)
        {
            try
            {
                var list = Web.Lists.TryGetList(Name);
                if (list != null)
                {
                    var listAdd = list.ContentTypes[contentTypeName];
                    return listAdd != null;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception exception)
            {
                Logger.Error(string.Concat("Add ContentType", exception.Message));
                return false;
            }
        }

Usage Example

Example #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;
     }
 }