public static bool SaveTemplate(string name, string description, ModuleInstanceContext context, bool forceOverwrite, int maxNumberOfRecords) { var doc = new XmlDocument(); var moduleInfo = new ModuleController().GetModule(context.Configuration.ModuleID, context.Configuration.TabID); var node = ModuleSerializationController.SerializeModule(doc, moduleInfo, true, maxNumberOfRecords); // add PaneName as element "name" var paneNode = doc.CreateElement("name"); paneNode.InnerXml = context.Configuration.PaneName; node.AppendChild(paneNode); var template = new TemplateInfo { Name = name, Description = description, ExportContent = XslTemplatingUtilities.PrettyPrint(node.OuterXml) }; var fileName = string.Format("{0}.{1}.module.template", Globals.CleanFileName(name), moduleInfo.DesktopModule.ModuleName.ToLowerInvariant()); var portalSettings = context.PortalSettings; var folder = Utilities.GetFolder(portalSettings, Definition.TemplateFolderName); if (Utilities.SaveScript(template.GetXml(), fileName, folder, forceOverwrite)) { ClearCache(); return(true); } return(false); }
void EditExistingScriptAndTemplates(IFileInfo file) { ViewState[Definition.XSLFolderName] = file.Folder; txtFolderName.Text = file.Folder; txtFileName.Text = file.FileName; txtFileName.MaxLength = Convert.ToInt32(200 - (ModuleContext.PortalSettings.HomeDirectoryMapPath + "/" + file.Folder).Length); string fileContent; using (var stream = FileManager.Instance.GetFileContent(file)) { using (var x = new StreamReader(stream)) { fileContent = x.ReadToEnd(); } } fileContent = fileContent.Replace(XslTemplatingUtilities.HardSpace, XslTemplatingUtilities.SpacePlaceholder); var doc = new XmlDocument(); doc.LoadXml(fileContent); var nameSpaceManager = new XmlNamespaceManager(doc.NameTable); nameSpaceManager.AddNamespace("udt", "DotNetNuke/UserDefinedTable"); nameSpaceManager.AddNamespace("xsl", "http://www.w3.org/1999/XSL/Transform"); var scriptRoot = doc.SelectSingleNode("/xsl:stylesheet", nameSpaceManager); var templateDefinition = // ReSharper disable PossibleNullReferenceException (XmlElement)(scriptRoot.SelectSingleNode("udt:template", nameSpaceManager)); if (templateDefinition != null) { if (templateDefinition.HasAttribute("headerView")) { txtHeaderTemplate.Text = (HttpUtility.HtmlDecode(templateDefinition.Attributes["headerView"].Value).Replace( XslTemplatingUtilities.SpacePlaceholder, XslTemplatingUtilities.HardSpace)); } if (templateDefinition.HasAttribute("listView")) { txtListTemplate.Text = (HttpUtility.HtmlDecode(templateDefinition.Attributes["listView"].Value).Replace( XslTemplatingUtilities.SpacePlaceholder, XslTemplatingUtilities.HardSpace)); } if (templateDefinition.HasAttribute("detailView")) { txtDetailTemplate.Text = (HttpUtility.HtmlDecode(templateDefinition.Attributes["detailView"].Value).Replace( XslTemplatingUtilities.SpacePlaceholder, XslTemplatingUtilities.HardSpace)); } chkEnablePaging.Checked = templateDefinition.HasAttribute("paging"); chkEnableSorting.Checked = templateDefinition.HasAttribute("sorting"); chkEnableSearch.Checked = templateDefinition.HasAttribute("searching"); chkShowDetailView.Checked = templateDefinition.HasAttribute("showDetailView"); if (templateDefinition.HasAttribute("isTrackingMode")) { IsTrackingEmailMode = true; txtTrackingEmailTemplate.Text = (HttpUtility.HtmlDecode(templateDefinition.Attributes["trackingEmail"].Value).Replace( XslTemplatingUtilities.SpacePlaceholder, XslTemplatingUtilities.HardSpace)); } if (templateDefinition.HasAttribute("listType")) { ddlListTemplateType.SelectedValue = templateDefinition.Attributes["listType"].Value; setupDelimiter(); } if (templateDefinition.HasAttribute("delimiter")) { txtListTemplateDelimiter.Text = HttpUtility.HtmlDecode(templateDefinition.Attributes["delimiter"].Value); } scriptRoot.RemoveChild(templateDefinition); } txtXslScript.Text = (XslTemplatingUtilities.PrettyPrint(doc).Replace(XslTemplatingUtilities.SpacePlaceholder, XslTemplatingUtilities.HardSpace)); ShowXslEditor(); // ReSharper restore PossibleNullReferenceException }