// Set the properties newTemplate.TemplateDisplayName = "My new issue template"; newTemplate.TemplateName = "MyNewIssueTemplate"; newTemplate.TemplateType = EmailTemplateType.Issue; newTemplate.TemplateBody = "<p>My new issue template body</p><p>$$content:800:600$$</p>"; newTemplate.TemplateHeader = "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title>Newsletter< title><meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\" /></head><body>"; newTemplate.TemplateFooter = "</body></html>"; newTemplate.TemplateSiteID = CMSContext.CurrentSiteID;
// Save the issue template EmailTemplateProvider.SetEmailTemplate(newTemplate); }
The following example gets and updates an issue template.
privatebool GetAndUpdateIssueTemplate() { // Get the issue template EmailTemplate updateTemplate = EmailTemplateProvider.GetEmailTemplate("MyNewIssueTemplate", CMSContext.CurrentSiteID); if (updateTemplate != null) { // Update the properties updateTemplate.TemplateDisplayName = updateTemplate.TemplateDisplayName.ToLower();
// Save the changes EmailTemplateProvider.SetEmailTemplate(updateTemplate);
returntrue; }
returnfalse; }
The following example gets and bulk updates issue templates.
privatebool GetAndBulkUpdateIssueTemplates() { // Prepare the parameters string where = "TemplateName LIKE N'MyNewIssueTemplate%'";
// Get the data DataSet templates = EmailTemplateProvider.GetEmailTemplates(where, null); if (!DataHelper.DataSourceIsEmpty(templates)) { // Loop through the individual items foreach (DataRow templateDr in templates.Tables[0].Rows) { // Create object from DataRow EmailTemplate modifyTemplate = newEmailTemplate(templateDr);
// Update the properties modifyTemplate.TemplateDisplayName = modifyTemplate.TemplateDisplayName.ToUpper();
// Save the changes EmailTemplateProvider.SetEmailTemplate(modifyTemplate); }
returntrue; }
returnfalse; }
The following example deletes a subscription template.
privatebool DeleteSubscriptionTemplate() { // Get the subscription template EmailTemplate deleteTemplate = EmailTemplateProvider.GetEmailTemplate("MyNewSubscriptionTemplate", CMSContext.CurrentSiteID);
// Delete the subscription template EmailTemplateProvider.DeleteEmailTemplate(deleteTemplate);
return (deleteTemplate != null); }
The following example deletes an unsubscription template.
privatebool DeleteUnsubscriptionTemplate() { // Get the unsubscription template EmailTemplate deleteTemplate = EmailTemplateProvider.GetEmailTemplate("MyNewUnsubscriptionTemplate", CMSContext.CurrentSiteID);
// Delete the unsubscription template EmailTemplateProvider.DeleteEmailTemplate(deleteTemplate);
return (deleteTemplate != null); }
The following example deletes an issue template.
privatebool DeleteIssueTemplate() { // Get the issue template EmailTemplate deleteTemplate = EmailTemplateProvider.GetEmailTemplate("MyNewIssueTemplate", CMSContext.CurrentSiteID);
// Delete the issue template EmailTemplateProvider.DeleteEmailTemplate(deleteTemplate);