/// <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 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()); }