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 4) - Moving Template Galleries and Templates

3/19/2011 9:26:15 PM

Moving Template Galleries and Templates

Template galleries and templates are moved using Template Explorer or Site Manager by dragging and dropping the object from one container into another. The PAPI offers the TemplateGalleryItem.MoveTo() method to move these objects programmatically.

The technique is similar to copying templates. Here’s what we need to do:

  • First, get a reference to the template gallery item that we wish to move.

  • Next, get a reference to the destination template gallery that the template gallery item is to be moved to.

  • Finally, call the TemplateGalleryItem.MoveTo() method.

Let’s build a Move Template dialog for CMS Explorer.

Add a web form named MoveTemplate.aspx to the project.

1.
Drag and drop styles.css onto the web form.

2.
In HTML view, enter the following code:

<table>
<tr>
<td colspan="2">
<h1>Move Template</h1>
(Add Literal for displaying the path here)
</td>
</tr>
<tr>
<td>Destination Gallery:</td>
<td>
(Add the text box for the destination gallery 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 Move Template button here)
<INPUT type="button" value="Close"
onclick="javascript:window.close();">
</td>
</tr>
</table>


3.
Toggle to Design view. Drag and drop the following controls from the Web Forms section of the Toolbox and set their properties as shown below:

ControlPropertyValue
LiteralIDlitOriginalTemplate
TextBoxIDtxtDestination
LabelIDlblErrorMessage
 Text(empty string)
ButtonIDbtnMove
 TextMove Template

When completed, the web form appears in Design view as shown below:

4.
Double-click on the form to get to its code-behind file. Add the Microsoft.ContentManagement.Publishing namespace:

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

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

5.
In the Page_Load() event handler, we get an instance of the template to be moved. In previous examples, we did a check to see if the user has rights to work with an item only after the user has clicked on the button. Let’s try a different approach this time. Instead of returning an error message to users who do not have the necessary permissions, we will enable or disable the button accordingly.

We check to see if the user has rights to move the template by checking the Template.CanMove property value. If Template.CanMove returns true, it means that the user is either an administrator or assigned to a rights group that belongs to a channel manager or template designer role of the current template gallery. If the user has the rights to move the template, we keep the btnMove button enabled; otherwise, it’s disabled.

private CmsHttpContext cmsContext;
private Template originalTemplate;

private void Page_Load(object sender, System.EventArgs e)
{
cmsContext = CmsHttpContext.Current;
// Clear all error messages, if any.
lblErrorMessage.Text = String.Empty;
// Get an instance of the original template
string cmsObjectGuid = String.Empty;
if (Request.QueryString["CMSObjectGuid"] != null)
{
cmsObjectGuid = Request.QueryString["CMSObjectGuid"];
originalTemplate = cmsContext.Searches.GetByGuid(cmsObjectGuid)
as Template;
if (originalTemplate != null)
{
// Display the template's path
litOriginalTemplate.Text = originalTemplate.Path;
if (originalTemplate.CanMove)
{
btnMove.Enabled = true;
}
else
{
// we can't move this template.
lblErrorMessage.Text = "You do not have rights to "
+ "move this template.";
btnMove.Enabled = false;
}
}
else
{
// Uh-oh we can't get an instance of the template.
lblErrorMessage.Text = "Original Template not found!";
}
}
}


6.
Next, we get an instance of the destination template gallery. We perform the move operation only if the user has rights to create templates in the destination template gallery. Once we have ascertained that the destination template gallery is valid, we will call the Template.MoveTo() method, passing the instance of the destination template gallery as an input parameter. After moving a template, its state is Saved.

Until the call to Template.Submit() is made for the template that has been moved, other template designers are not be able to modify the moved template or any of its connected templates. Toggle to Design view and double-click on the btnMove button to get to the btnMove_Click() event handler. Add the code shown below:

private void btnMove_Click(object sender, System.EventArgs e)
{
try
{
// Moving a template
// get the destination template gallery
TemplateGallery destinationGallery;
string destinationGalleryPath = txtDestination.Text;
destinationGallery = cmsContext.Searches.GetByPath(
destinationGalleryPath) as TemplateGallery;
if (destinationGallery!=null)
{
if (destinationGallery.CanCreateTemplates)
{
// move the template
originalTemplate.MoveTo(destinationGallery);
// commit the move to the repository and its state
// changes to "Saved"
cmsContext.CommitAll();
// submit it to change its state from "Saved" to "Published"
// and to make it available to other template designers
if (originalTemplate.CanSubmit)
{
originalTemplate.Submit();
cmsContext.CommitAll();
}
// display the success message
lblErrorMessage.Text = "Template moved successfully!";
}
else
{
// We do not have rights to create templates
// in the specified destination template gallery
lblErrorMessage.Text = "You do not have rights to "
+ "create templates in the "
+ "destination template gallery.";
}
}
else
{
// We can't get an instance of the destination template gallery.
lblErrorMessage.Text = "Destination Template Gallery not found!";
}
}
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;
}
}


Let’s move a template!

1.
Navigate to the MyTemplate template that was created earlier.

2.
Click Edit | Move.

3.
In the Destination Gallery field, enter /templates/tropicalgreen/.

4.
Click Move Template.

5.
Click Close to close the dialog.

6.
Back at the CMS Explorer interface, navigate to the TropicalGreen template gallery, which now contains the template, MyTemplate.

Can I use the PAPI to move template galleries?

No, template galleries can only be moved using Site Manager or Template Explorer (available in Visual Studio .NET) by dragging the template gallery and dropping it into the destination.

When template galleries are moved, all templates within it are also moved. However, unlike moving templates, moving a template gallery does not change the state of the templates it contains.

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 video Game
-   Uncharted 4: A Thief's End | E3 2015 Extended Gameplay Trailer
-   V.Next [PC] Kickstarter Trailer
-   Renowned Explorers [PC] Launch Date Trailer
-   The Void (Game Trailer)
-   World of Warships [PC] Open Beta Trailer
-   F1 2015 | Features Trailer
-   Battle Fantasia Revised Edition | Debut Trailer for Steam
-   Victor Vran [PC] Story Trailer
-   Star Wars Battlefront PC Alpha footage
-   Skyforge [PC] Open Beta Gameplay Trailer
-   Armored Warfare [PC] PvE Trailer
-   F1 2015 [PS4/XOne/PC] Features Trailer
-   Act of Aggression [PC] Pre-Order Trailer
-   Sword Coast Legends [PC] Campaign Creation E3 2015 Trailer
-   Sword Coast Legends [PC] Campaign Creation E3 2015 Dungeon Run Trailer
Popular tags
Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 windows Phone 7 windows Phone 8
programming4us programming4us
 
Popular keywords
HOW TO Swimlane in Visio Visio sort key Pen and Touch Creating groups in Windows Server Raid in Windows Server Exchange 2010 maintenance Exchange server mail enabled groups Debugging Tools Collaborating
programming4us programming4us
PS4 game trailer XBox One game trailer
WiiU game trailer 3ds game trailer
Trailer game
 
programming4us
Natural Miscarriage
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Game Trailer