本文整理汇总了C#中umbraco.cms.businesslogic.template.Template.SaveAsMasterPage方法的典型用法代码示例。如果您正苦于以下问题:C# Template.SaveAsMasterPage方法的具体用法?C# Template.SaveAsMasterPage怎么用?C# Template.SaveAsMasterPage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类umbraco.cms.businesslogic.template.Template
的用法示例。
在下文中一共展示了Template.SaveAsMasterPage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SaveMasterPageFile
public void SaveMasterPageFile(string masterPageContent)
{
// Add header to master page if it doesn't exist
if (!masterPageContent.StartsWith("<%@"))
{
masterPageContent = getMasterPageHeader() + "\n" + masterPageContent;
}
else
{
// verify that the masterpage attribute is the same as the masterpage
string masterHeader = masterPageContent.Substring(0, masterPageContent.IndexOf("%>") + 2).Trim(Environment.NewLine.ToCharArray());
// find the masterpagefile attribute
MatchCollection m = Regex.Matches(masterHeader, "(?<attributeName>\\S*)=\"(?<attributeValue>[^\"]*)\"",
RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
foreach (Match attributeSet in m)
{
if (attributeSet.Groups["attributeName"].Value.ToLower() == "masterpagefile")
{
// validate the masterpagefile
string currentMasterPageFile = attributeSet.Groups["attributeValue"].Value;
string currentMasterTemplateFile = currentMasterTemplateFileName();
if (currentMasterPageFile != currentMasterTemplateFile)
{
masterPageContent =
masterPageContent.Replace(
attributeSet.Groups["attributeName"].Value + "=\"" + currentMasterPageFile + "\"",
attributeSet.Groups["attributeName"].Value + "=\"" + currentMasterTemplateFile + "\"");
}
}
}
}
//we have a Old Alias if the alias and therefor the masterpage file name has changed...
//so before we save the new masterfile, we'll clear the old one, so we don't up with
//Unused masterpage files
if (!string.IsNullOrEmpty(_oldAlias) && _oldAlias != _alias)
{
//Ensure that child templates have the right master masterpage file name
if (HasChildren)
{
//store children array here because iterating over an Array property object is very inneficient.
var c = Children;
foreach (CMSNode cmn in c)
{
Template t = new Template(cmn.Id);
t.SaveAsMasterPage();
t.Save();
}
}
//then kill the old file..
string _oldFile = IOHelper.MapPath(SystemDirectories.Masterpages + "/" + _oldAlias.Replace(" ", "") + ".master");
if (System.IO.File.Exists(_oldFile))
System.IO.File.Delete(_oldFile);
}
// save the file in UTF-8
File.WriteAllText(MasterPageFile, masterPageContent, System.Text.Encoding.UTF8);
}