public ActionResult SaveSiteAsTemplate(SaveTemplateViewModel model, HttpPostedFileBase templateImageFile) { AntiForgery.Validate(); if (ModelState.IsValid) { // Prepare the Job to store the Provisioning Template GetProvisioningTemplateJob job = new GetProvisioningTemplateJob(); // Store the local location for the Provisioning Template, if any String storageLocationUrl = null; // Determine the Scope of the Provisioning Template using (var ctx = PnPPartnerPackContextProvider.GetAppOnlyClientContext(model.SourceSiteUrl)) { Web web = ctx.Web; Web rootWeb = ctx.Site.RootWeb; ctx.Load(web, w => w.Id); ctx.Load(rootWeb, w => w.Url, w => w.Id); ctx.ExecuteQueryRetry(); if (web.Id == rootWeb.Id) { // We are in the Root Site of the Site Collection job.Scope = TemplateScope.Site; storageLocationUrl = rootWeb.Url; } else { // Otherwise we are in a Sub Site of the Site Collection job.Scope = TemplateScope.Web; } } // Prepare all the other information about the Provisioning Job job.Owner = ClaimsPrincipal.Current.Identity.Name; job.FileName = model.FileName; job.IncludeAllTermGroups = model.IncludeAllTermGroups; job.IncludeSearchConfiguration = model.IncludeSearchConfiguration; job.IncludeSiteCollectionTermGroup = model.IncludeSiteCollectionTermGroup; job.IncludeSiteGroups = model.IncludeSiteGroups; job.PersistComposedLookFiles = model.PersistComposedLookFiles; job.SourceSiteUrl = model.SourceSiteUrl; job.Title = model.Title; job.Description = model.Description; job.Location = (ProvisioningTemplateLocation)Enum.Parse(typeof(ProvisioningTemplateLocation), model.Location, true); job.StorageSiteLocationUrl = storageLocationUrl; if (templateImageFile != null && templateImageFile.ContentLength > 0) { job.TemplateImageFile = templateImageFile.InputStream.FixedSizeImageStream(320, 180).ToByteArray(); job.TemplateImageFileName = templateImageFile.FileName; } model.JobId = ProvisioningRepositoryFactory.Current.EnqueueProvisioningJob(job); } return(View(model)); }
public ActionResult SaveSiteAsTemplate(String spHostUrl) { SaveTemplateViewModel model = new SaveTemplateViewModel(); model.SourceSiteUrl = spHostUrl; model.IncludeAllTermGroups = false; model.IncludeSiteCollectionTermGroup = false; return(View(model)); }