public ActionResult DeleteAll() { //return RedirectToAction("Index"); DocumentSetTemplate template = null; List <ContentTypeModel> model = new List <ContentTypeModel>(); var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext); using (var clientContext = spContext.CreateUserClientContextForSPHost()) { if (clientContext != null) { Web web = clientContext.Web; clientContext.Load(web, w => w.ContentTypes, w => w.Fields); clientContext.ExecuteQuery(); foreach (ContentType ct in web.ContentTypes) { //find out documentset and child content type if (ct.Name.IndexOf("document set", StringComparison.CurrentCultureIgnoreCase) != -1 || DocumentSetTemplate.IsChildOfDocumentSetContentType(clientContext, ct).Value) { template = DocumentSetTemplate.GetDocumentSetTemplate(clientContext, ct); clientContext.Load(template, t => t.AllowedContentTypes, t => t.DefaultDocuments, t => t.SharedFields, t => t.WelcomePageFields); clientContext.ExecuteQuery(); foreach (ContentTypeId ctId in template.AllowedContentTypes) { ContentType ctAllowed = clientContext.Web.ContentTypes.First(d => d.StringId == ctId.StringValue); if (ctAllowed != null) { model.Add(new ContentTypeModel() { Id = ctId, Name = ctAllowed.Name }); } } break; } } } } return(View("AllowedContentTypesDeleteAll", model)); }
public ActionResult AllowedContentTypeDeleteAll() { DocumentSetTemplate template = null; List <ContentTypeModel> model = new List <ContentTypeModel>(); var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext); using (var clientContext = spContext.CreateUserClientContextForSPHost()) { if (clientContext != null) { Web web = clientContext.Web; clientContext.Load(web, w => w.ContentTypes, w => w.Fields); clientContext.ExecuteQuery(); foreach (ContentType ct in web.ContentTypes) { //find out documentset and child content type if (ct.Name.IndexOf("document set", StringComparison.CurrentCultureIgnoreCase) != -1 || DocumentSetTemplate.IsChildOfDocumentSetContentType(clientContext, ct).Value) { template = DocumentSetTemplate.GetDocumentSetTemplate(clientContext, ct); clientContext.Load(template, t => t.AllowedContentTypes, t => t.DefaultDocuments, t => t.SharedFields, t => t.WelcomePageFields); clientContext.ExecuteQuery(); List <ContentTypeId> delList = new List <ContentTypeId>(); foreach (ContentTypeId ctId in template.AllowedContentTypes) { delList.Add(ctId); } //remove recorded content type id from allowedContentTypes list. delList.ForEach(ctId => template.AllowedContentTypes.Remove(ctId)); break; } } } } return(RedirectToAction("Index", new { SPHostUrl = SharePointContext.GetSPHostUrl(HttpContext.Request).AbsoluteUri })); }