Example #1
0
        public ActionResult CreateWeb(NewWebProperties props)
        {
            var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);

            // Uses SPHost context and creates a subsite in the host web
            using (var cc = spContext.CreateUserClientContextForSPHost())
            {
                Web newWeb = cc.Web.CreateWeb(props.Title, props.Url, "", props.SelectedWebTemplate, 1033);

                cc.Load(newWeb);
                cc.ExecuteQueryRetry();

                // Convert the URL to absolute so we can provide a link to the new subsite
                props.Url = newWeb.Url;
                return(View(props));
            }
        }
Example #2
0
        public ActionResult Scenario1()
        {
            var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);

            using (var cc = spContext.CreateAppOnlyClientContextForSPHost())
            {
                cc.Load(cc.Web);
                cc.ExecuteQueryRetry();

                // Get all of the WebTemplates so we can pass it to NewWebProperties to populate the SelectListItems
                WebTemplateCollection webTemplates = cc.Web.GetAvailableWebTemplates(cc.Web.Language, false);
                cc.Load(webTemplates);
                cc.ExecuteQueryRetry();

                var props = new NewWebProperties(webTemplates);
                return(View(props));
            }
        }