var taxonomyManager = TaxonomyManager.GetManager();
var node = taxonomyManager.GetTaxon<HierarchicalTaxon>(BackendTemplatesCategoryId);
var pageManager = PageManager.GetManager();
var template = pageManager.GetTemplate(
new
Guid(
"2BFF6C39-1918-4F1E-9D5C-9584578C97D2"
));
template.Name =
"Test2"
;
template.Title =
template.Category = node.Id;
template.Ordinal = 9;
var present = pageManager.GetPresentationItem<TemplatePresentation>();
present.DataType = Presentation.HtmlDocument;
present.Name =
"master1"
var resName =
"Samples.Templates.FrontEndTemplate.aspx"
present.Data = ControlUtilities.GetTextResource(resName,
this
.GetType());
template.Presentation.Add(present);
present = pageManager.GEtPresentationItem<TemplatePresentation>();
present.DataType = Presentation.ImageUrl;
"icon"
present.Theme =
null
present.Data =
"Samples.Templates.images.back.gif"
template.Controls.Add(ctrlD
<%@ Page Language="C#" AutoEventWireup="true" Inherits="System.Web.UI.Page" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="Telerik.Sitefinity.Modules.Pages" %>
<%@ Import Namespace="Telerik.Sitefinity.Pages.Model" %>
<%@ Import Namespace="Telerik.Sitefinity.Security" %>
<
script
runat
=
"server"
>
private const string IconsDirectory = "~/Static/Thumbnails";
protected void Page_Load(object sender, EventArgs e)
if (!this.IsPostBack)
PageManager pageManager = PageManager.GetManager();
this.templateList.DataSource = pageManager.GetTemplates().OrderBy(t => t.Title);
this.templateList.DataBind();
protected void SetIcon(object sender, EventArgs e)
this.errorMessage.Visible = false;
this.successMessage.Visible = false;
if (!this.iconUpload.HasFile)
this.errorMessage.Text = "You must upload an image";
this.errorMessage.Visible = true;
return;
PageTemplate template = pageManager.GetTemplate(Guid.Parse(this.templateList.SelectedValue));
if (!template.IsGranted(SecurityConstants.Sets.PageTemplates.SetName, SecurityConstants.Sets.PageTemplates.Modify))
this.errorMessage.Text = "You do not have permission to modify this template";
System.Drawing.Image iconBitmap = System.Drawing.Image.FromStream(this.iconUpload.FileContent);
System.Drawing.Image largeIcon = iconBitmap.GetThumbnailImage(105, 79, delegate() return false; , IntPtr.Zero);
System.Drawing.Image smallIcon = iconBitmap.GetThumbnailImage(42, 32, delegate() return false; , IntPtr.Zero);
iconBitmap.Dispose();
string largePath = IconsDirectory + "/" + this.templateList.SelectedValue + ".Icon.png";
string smallPath = Path.Combine(this.Server.MapPath(IconsDirectory), this.templateList.SelectedValue + ".sml_Icon.png");
largeIcon.Save(this.Server.MapPath(largePath), ImageFormat.Png);
largeIcon.Dispose();
smallIcon.Save(smallPath, ImageFormat.Png);
smallIcon.Dispose();
TemplatePresentation urlPresent = template.Presentation.FirstOrDefault(p => p.DataType == Presentation.ImageUrl && p.Name == "icon");
if (urlPresent == null)
urlPresent = pageManager.CreatePresentationItem<
TemplatePresentation
>();
urlPresent.DataType = Presentation.ImageUrl;
urlPresent.Template = template;
urlPresent.Theme = null;
urlPresent.Name = "icon";
template.Presentation.Add(urlPresent);
urlPresent.Data = largePath;
pageManager.SaveChanges();
this.successMessage.Text = "The new icon has been set for " + template.Title;
this.successMessage.Visible = true;
protected void ResetIcon(object sender, EventArgs e)
if (urlPresent != null && urlPresent.Data.StartsWith(IconsDirectory, StringComparison.CurrentCultureIgnoreCase))
try
File.Delete(this.Server.MapPath(urlPresent.Data));
catch
string smallPath = urlPresent.Data;
string[] smallParts = smallPath.Split('.').Where(s => !String.IsNullOrWhiteSpace(s)).ToArray();
if (smallParts.Length > 1)
smallParts[smallParts.Length - 2] = "sml_" + smallParts[smallParts.Length - 2];
smallPath = String.Join(".", smallParts);
File.Delete(this.Server.MapPath(smallPath));
template.Presentation.Remove(urlPresent);
this.successMessage.Text = "The icon has been reset for " + template.Title;
</
<!DOCTYPE html>
html
xmlns
"http://www.w3.org/1999/xhtml"
head
title
>Custom Template Icon</
body
form
div
asp:Label
ID
"errorMessage"
Visible
"false"
ForeColor
"White"
BackColor
"Red"
/>
"successMessage"
"Green"
br
strong
>Template:</
asp:DropDownList
"templateList"
DataTextField
"Title"
DataValueField
"Id"
>Icon:</
asp:FileUpload
"iconUpload"
/><
asp:Button
"submitButton"
Text
"Set Icon"
OnClick
"SetIcon"
"resetButton"
"Reset Icon to Default"
"ResetIcon"
OnClientClick
"if (!confirm('Are you sure you want to reset the icon to the default custom icon?')) return false;"