本文整理汇总了C#中Web.SetAvailableWebTemplates方法的典型用法代码示例。如果您正苦于以下问题:C# Web.SetAvailableWebTemplates方法的具体用法?C# Web.SetAvailableWebTemplates怎么用?C# Web.SetAvailableWebTemplates使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Web
的用法示例。
在下文中一共展示了Web.SetAvailableWebTemplates方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProvisionObjects
public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation)
{
using (var scope = new PnPMonitoredScope(this.Name))
{
var site = (web.Context as ClientContext).Site;
var webFeatureActive = web.IsFeatureActive(PUBLISHING_FEATURE_WEB);
var siteFeatureActive = site.IsFeatureActive(PUBLISHING_FEATURE_SITE);
if (template.Publishing.AutoCheckRequirements == AutoCheckRequirementsOptions.SkipIfNotCompliant && !webFeatureActive)
{
scope.LogDebug("Publishing Feature (Web Scoped) not active. Skipping provisioning of Publishing settings");
return parser;
}
else if (template.Publishing.AutoCheckRequirements == AutoCheckRequirementsOptions.MakeCompliant)
{
if (!siteFeatureActive)
{
scope.LogDebug("Making site compliant for publishing");
site.ActivateFeature(PUBLISHING_FEATURE_SITE);
web.ActivateFeature(PUBLISHING_FEATURE_WEB);
}
else
{
if (!web.IsFeatureActive(PUBLISHING_FEATURE_WEB))
{
scope.LogDebug("Making site compliant for publishing");
web.ActivateFeature(PUBLISHING_FEATURE_WEB);
}
}
}
else
{
throw new Exception("Publishing Feature not active. Provisioning failed");
}
// Set allowed web templates
var availableWebTemplates = template.Publishing.AvailableWebTemplates.Select(t => new WebTemplateEntity() { LanguageCode = t.LanguageCode.ToString(), TemplateName = t.TemplateName }).ToList();
if (availableWebTemplates.Any())
{
web.SetAvailableWebTemplates(availableWebTemplates);
}
// Set allowed page layouts
var availablePageLayouts = template.Publishing.PageLayouts.Select(p => p.Path);
if (availablePageLayouts.Any())
{
web.SetAvailablePageLayouts(site.RootWeb, availablePageLayouts);
}
// Set default page layout, if any
var defaultPageLayout = template.Publishing.PageLayouts.FirstOrDefault(p => p.IsDefault);
if (defaultPageLayout != null)
{
web.SetDefaultPageLayoutForSite(site.RootWeb, defaultPageLayout.Path);
}
if (template.Publishing.DesignPackage != null)
{
var package = template.Publishing.DesignPackage;
var tempFileName = Path.Combine(Path.GetTempPath(), template.Connector.GetFilenamePart(package.DesignPackagePath));
scope.LogDebug("Saving {0} to temporary file: {1}", package.DesignPackagePath, tempFileName);
using (var stream = template.Connector.GetFileStream(package.DesignPackagePath))
{
using (var outstream = System.IO.File.Create(tempFileName))
{
stream.CopyTo(outstream);
}
}
scope.LogDebug("Installing design package");
site.InstallSolution(package.PackageGuid, tempFileName, package.MajorVersion, package.MinorVersion);
System.IO.File.Delete(tempFileName);
}
return parser;
}
}