Esempio n. 1
0
        public ActionResult AddAllowedContentTypeAction([Bind(Include = "SelectedStringId")] AddAllowedContentTypeViewModel model)
        {
            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();

                    var query = from ct in web.ContentTypes
                                where ct.Id.StringValue == model.SelectedStringId
                                select ct;
                    ContentType ctFound = query.First();

                    DocumentSetTemplate template = GetDocumentSetTemplate(clientContext);
                    if (template != null)
                    {
                        template.AllowedContentTypes.Add(ctFound.Id);
                        template.Update(true);
                        clientContext.Load(template);
                        clientContext.ExecuteQuery();
                    }
                }
            }

            return(RedirectToAction("Index", new { SPHostUrl = SharePointContext.GetSPHostUrl(HttpContext.Request).AbsoluteUri }));
        }
Esempio n. 2
0
        public ActionResult AddAllowedContentType()
        {
            //return RedirectToAction("Index");
            AddAllowedContentTypeViewModel model = new AddAllowedContentTypeViewModel();

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

                    List <ContentTypeModel> allContentTypes = new List <ContentTypeModel>();
                    foreach (ContentType ct in web.ContentTypes)
                    {
                        allContentTypes.Add(new ContentTypeModel()
                        {
                            Name = ct.Name, Id = ct.Id
                        });
                    }
                    ViewBag.SelectedStringId = new SelectList(allContentTypes, "StringId", "Name", model.SelectedStringId);
                }
            }
            return(View("AddAllowedContentType", model));
        }