Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
Windows Server

Microsoft Content Management Server : Managing Template Galleries and Templates (part 1) - Creating Template Galleries

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
3/19/2011 9:17:01 PM
Out of the box, you can choose to manage template galleries and templates using either Site Manager or Template Explorer, which might be OK if you are using Visual Studio .NET as your development tool (as recommended). A compelling reason to write an administrative module to manage template galleries and templates is to work with them without having to open VS.NET. We have found this particularly useful when attempting to work in an environment where VS.NET is not installed such as on a production or a staging server. Or perhaps business requirements call for certain actions to be performed when a template gallery or template is created. Whatever the occasions may be, you may need to modify template gallery and template properties, placeholder definition and custom property collections through code.

The PAPI offers a wide range of methods and properties to work with template galleries and templates. We explore the most frequently used methods in this section, beginning with the creation of template galleries.

Creating Template Galleries

Template galleries can be created from both Site Manager and Template Explorer. Now we will show you how we can create them from code. Let’s add a Create Template Gallery dialog to the CMS Explorer interface.

1.
Add a new web form to the project with the name CreateTemplateGallery.aspx.

2.
In Design view, drag and drop styles.css from Solution Explorer onto the web form.

3.
Toggle to HTML view. Insert a table with five rows. Code it in the same way as shown overleaf. A level-1 heading with the text Create Template Gallery forms the first row. The rest of the table consists of text labels and temporary markers indicating where the controls should go later.

<table>
<tr>
<td colspan="2">
<h1>Create Template Gallery</h1>
<h2>
Parent Template Gallery:
(Add Literal for displaying the path here)
</h2>
</td>
</tr>
<tr>
<td>Name:</td>
<td>(Add the text box for the Name here)</td>
</tr>
<tr>
<td>Description:</td>
<td>(Add the text box for the Description here)</td>
</tr>
<tr>
<td colspan="2">
(Add the Label for displaying error messages here)
</td>
</tr>
<tr>
<td colspan="2" align="right">
(Add the Create Gallery button here)
<INPUT type="button" value="Close"
onclick="javascript:window.close();">
</td>
</tr>
</table>


4.
Switch back to Design view, drag the following controls from the Web Forms section of the Toolbox onto the form and delete the text markers. Arrange them as shown in the following diagram. Template galleries only have Name and Description properties to modify.

ControlPropertyValue
LiteralIDlitParentGallery
TextBoxIDtxtName
TextBoxIDtxtDescription
 Rows3
 TextModeMultiLine
LabelIDlblErrorMessage
 Text(empty string)
ButtonIDbtnCreate
 TextCreate Gallery

5.
Add the Microsoft.ContentManagement.Publishing namespace to the code-behind file:

. . . code continues . . .
// MCMS API
using Microsoft.ContentManagement.Publishing;

namespace CmsExplorer
{
. . . code continues . . .
}

6.
In the Page_Load() event handler, we get the GUID of the parent template gallery from the CMSObjectGuid querystring parameter, and pass it to the Searches.GetByGuid() method to get a reference to the gallery itself.

TemplateGallery parentGallery;
CmsHttpContext cmsContext;

private void Page_Load(object sender, System.EventArgs e)
{
cmsContext = CmsHttpContext.Current;
lblErrorMessage.Text = String.Empty;
string cmsObjectGuid = String.Empty;
if (Request.QueryString["CMSObjectGuid"] != null)
{
cmsObjectGuid = Request.QueryString["CMSObjectGuid"];
parentGallery = cmsContext.Searches.GetByGuid(cmsObjectGuid) as
TemplateGallery;
if (parentGallery != null)
{
litParentGallery.Text = parentGallery.Path;
}
else
{
lblErrorMessage.Text = "Parent Gallery not found!";
}
}
}


7.
Toggle to Design view and double-click on the btnCreate button. In the btnCreate_Click() event handler, add the following code:

private void btnCreate_Click(object sender, System.EventArgs e)
{
try
{
if (parentGallery.CanCreateTemplateGalleries)
{
// get the template gallery's name
string name = txtName.Text.Trim();
if (!Utility.ValidateMCMSObjectName(name))
{
throw new Exception("Specified template gallery name is not "
+ "valid. Must be only alphanumeric "
+ "characters, open or close parens, "
+ "hyphens, underscores, periods, or "
+ "spaces. No period at the end and no "
+ "consecutive periods are allowed. ");
}
// create the template gallery
TemplateGallery newGallery;
newGallery = parentGallery.CreateTemplateGallery();
newGallery.Name = name;
newGallery.Description = txtDescription.Text;
cmsContext.CommitAll();
// display the success message
lblErrorMessage.Text = "Template Gallery created successfully!";
}
else
{
lblErrorMessage.Text = "You do not have rights to create a "
+ "template gallery.";
}
}
catch (Exception ex)
{
// rollback all changes
cmsContext.RollbackAll();
// the CMS context needs to be disposed of after a rollback
cmsContext.Dispose();
// display error message
lblErrorMessage.Text = ex.Message;
}
}


Before creating the template gallery, the code performs a couple of validation checks to see if:

  • The user has the rights to create sub-template galleries in the parent template gallery. This is done by checking that the TemplateGallery.CanCreateTemplateGalleries property returns a Boolean true.

  • The name supplied by the user is a valid template gallery name. A valid name contains only the characters, A-Z, a-z, 0-9,-, _, (space), (), and periods. It should also not end with a period or contain two or more consecutive periods. 

If all validation checks pass, the code uses the TemplateGallery.CreateTemplateGallery() method to create a new template gallery object. We then set the gallery’s Name and Description properties to the values entered in the textboxes. As before, we call the CmsHttpContext.CommitAll() method to save the new template gallery to the repository.

Save and build the solution. Let’s create a template gallery with our new dialog:

1.
From the CMS Explorer interface, click Templates.

2.
Select New | New Template Gallery.

3.
In the New Template Gallery dialog, enter the following values:

PropertyValue
NameMyTemplateGallery
DescriptionThis template gallery was created from the PAPI

4.
Click Create Gallery and close the dialog. Refresh CMS Explorer and check that the new template gallery is created in the root template gallery. As an exercise, you could program the dialog to close itself and refresh the parent page automatically.
Other -----------------
- Integrating Exchange Server 2010 in a Non-Windows Environment : Administrative Improvements with Windows Server 2008
- Integrating Exchange Server 2010 in a Non-Windows Environment : Understanding the Identity Management for UNIX Components
- Using Services for UNIX to Integrate UNIX Systems with an Active Directory/Exchange Server 2010 Environment (part 3)
- Using Services for UNIX to Integrate UNIX Systems with an Active Directory/Exchange Server 2010 Environment (part 2) - Installing Services for Network File Server (NFS)
- Using Services for UNIX to Integrate UNIX Systems with an Active Directory/Exchange Server 2010 Environment (part 1)
- Managing Identity Information Between LDAP Directories and Exchange Server 2010
- Exchange Server 2010 : Synchronizing Directory Information with Forefront Identity Manager (FIM)
- Windows Server 2008 R2 : Using Operations Manager 2007 R2 (part 2) - Scheduling Reports
- Windows Server 2008 R2 : Using Operations Manager 2007 R2 (part 1) - Alert Tuning
- Windows Server 2008 R2 : Monitoring DMZ Servers with Certificates
 
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
 
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server