/// <summary> /// Removes a content type from a list/library by name /// </summary> /// <param name="list">The list</param> /// <param name="contentTypeName">The content type name to remove from the list</param> /// <exception cref="System.ArgumentException">Thrown when a arguement is null or <see cref="String.Empty"/></exception> public static void RemoveContentTypeByName(this List list, string contentTypeName) { if (string.IsNullOrEmpty(contentTypeName)) { var message = string.Format(Constants.EXCEPTION_MSG_INVALID_ARG, "contentTypeName"); throw new ArgumentNullException("contentTypeName", message); } ContentTypeCollection _cts = list.ContentTypes; list.Context.Load(_cts); IEnumerable <ContentType> _results = list.Context.LoadQuery <ContentType>(_cts.Where(item => item.Name == contentTypeName)); list.Context.ExecuteQuery(); ContentType _ct = _results.FirstOrDefault(); if (_ct != null) { _ct.DeleteObject(); list.Update(); list.Context.ExecuteQuery(); } }
public static void DeleteContentType(ClientContext clientContext, string contentTypeId, string contentTypeName) { ContentType ct = clientContext.Web.ContentTypes.GetById(contentTypeId); ct.DeleteObject(); clientContext.ExecuteQuery(); Console.WriteLine(contentTypeName + ": Deleted"); }
public static void DeleteContentType(this Web site, string name) { ContentType contentType = GetContentType(site, name); if (contentType != null) { contentType.DeleteObject(); site.Context.ExecuteQuery(); } }
private static void DeleteCtIfExists(string CTName) { ContentType ct = GetContentTypeByName(CTName); if (ct != null) { ct.DeleteObject(); context.ExecuteQuery(); web.Update(); } }
public static void RemoveContentType(this List list, string contentTypeName) { ContentTypeCollection _cts = list.ContentTypes; list.Context.Load(_cts); IEnumerable <ContentType> _results = list.Context.LoadQuery <ContentType>(_cts.Where(item => item.Name == contentTypeName)); list.Context.ExecuteQuery(); ContentType _ct = _results.FirstOrDefault(); if (_ct != null) { _ct.DeleteObject(); list.Update(); list.Context.ExecuteQuery(); } }
private void DeployHideContentTypeLinks(object modelHost, List list, RemoveContentTypeLinksDefinition contentTypeOrderDefinition) { var context = list.Context; context.Load(list, l => l.ContentTypes); context.ExecuteQueryWithTrace(); var listContentTypes = list.ContentTypes.ToList(); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, Object = list, ObjectType = typeof(List), ObjectDefinition = contentTypeOrderDefinition, ModelHost = modelHost }); // re-order foreach (var srcContentTypeDef in contentTypeOrderDefinition.ContentTypes) { ContentType listContentType = null; if (!string.IsNullOrEmpty(srcContentTypeDef.ContentTypeName)) { listContentType = listContentTypes.FirstOrDefault(c => c.Name == srcContentTypeDef.ContentTypeName); } if (listContentType == null && !string.IsNullOrEmpty(srcContentTypeDef.ContentTypeId)) { listContentType = listContentTypes.FirstOrDefault(c => c.Id.ToString().ToUpper().StartsWith(srcContentTypeDef.ContentTypeId.ToUpper())); } if (listContentType != null) { try { listContentType.DeleteObject(); } catch (Exception) { // TODO } } } InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = list, ObjectType = typeof(List), ObjectDefinition = contentTypeOrderDefinition, ModelHost = modelHost }); context.ExecuteQueryWithTrace(); }