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 : Copying Postings

- How To Install Windows Server 2012 On VirtualBox
- How To Bypass Torrent Connection Blocking By Your ISP
- How To Install Actual Facebook App On Kindle Fire
11/8/2011 9:11:42 AM
Postings can be copied from one channel to another or even to the same channel. Unlike connected postings, postings that are created from the copy action exist as independent entities. They do not share placeholder values, and so changes to the properties of the original posting do not affect the copy in any way.

Copying can be done using the Posting.CopyTo() method. Let’s create a Copy Posting dialog for CMS Explorer:

  1. Add a new web form to the CMSExplorer project. Name the new web form CopyPosting.aspx.

  2. In Design view, drag and drop the Styles.css file from Solution Explorer onto the form. This applies the stylesheet to the page.

  3. Toggle to HTML view and add the code as shown below for a table with four rows, between the <form> tags:

    <table>
    <tr>
    <td colspan="2">
    <h1>Copy Posting</h1>
    <h2>Original Path: (Add Literal for displaying the path here)</h2>
    </td>
    </tr>
    <tr>
    <td>Destination Channel:</td>
    <td>(Add the text box for the Destination Channel here)</td>
    <tr>
    <td colspan="2">(Add the Label for displaying error messages here)</td>
    </tr>
    <tr>
    <td colspan="2" align="right">
    (Add the Copy Posting button here)
    <INPUT type="button" value="Close"
    onclick="javascript:window.close();">
    </td>
    </tr>
    </table>
  4. Switch back to Design view. Drag and drop controls onto the web form and arrange them as shown in the screenshot overleaf.

    ControlPropertyProperty Value
    LiteralIDlitCurrentPosting
    TextBoxIDtxtDestination
    ButtonIDbtnCopy
     TextCopy Posting
    LabelIDlblErrorMessage
     Text(empty string)

  5. Double-click on the web form to get to its code-behind file. Import the Microsoft.ContentManagement.Publishing namespace. We will put the path of the posting we’re copying into the litCurrentPosting label within the Page_Load() event handler.

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

    namespace CmsExplorer
    {
    /// <summary>
    /// Summary description for CopyPosting.
    /// </summary>
    public class CopyPosting : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.TextBox txtDestination;
    protected System.Web.UI.WebControls.Label lblErrorMessage;
    protected System.Web.UI.WebControls.Button btnCopy;
    protected System.Web.UI.WebControls.Literal litCurrentPosting;

    private void Page_Load(object sender, System.EventArgs e)
    {
    // display the path of the posting to be copied
    Posting posting = CmsHttpContext.Current.Searches.GetByGuid(
    Request.QueryString["CMSObjectGuid"]) as Posting;
    if (posting != null)
    litCurrentPosting.Text = posting.Path;
    else
    lblErrorMessage.Text = "Requested posting does not exist.";
    }
    . . . code continues . . .

  6. Toggle back to Design view and double-click on the btnCopy button. In the btnCopy_Click() event handler, add the code as follows:

    private void btnCopy_Click(object sender, System.EventArgs e)
    {
    CmsHttpContext cmsContext = CmsHttpContext.Current;
    // get the posting to be copied
    Posting currentPosting;
    currentPosting = cmsContext.Searches.GetByGuid(
    Request.QueryString["CMSObjectGuid"]) as Posting;
    if (currentPosting != null)
    {
    try
    {
    // get the destination channel
    Channel destination;
    destination = cmsContext.Searches.GetByPath(
    txtDestination.Text) as Channel;
    if (destination != null)
    {
    // check if we can create postings
    if (!destination.CanCreatePostings)
    {
    throw new Exception("Current user does not have "
    + "permissions to create postings "
    + "in channel: " + destination.Path);
    }
    // copy the posting
    Posting copiedPosting;
    copiedPosting = currentPosting.CopyTo(destination);
    // you can proceed to set the properties of the
    // copied posting
    // e.g. copiedPosting.DisplayName =
    // "A Copy of the posting";
    // commit the changes
    cmsContext.CommitAll();
    // display the success message
    lblErrorMessage.Text = "Posting copied successfully!";
    }
    else
    {
    // cannot access the destination channel
    lblErrorMessage.Text = "Invalid Destination channel path";
    }
    }
    catch(Exception ex)
    {
    // rollback the changes
    cmsContext.RollbackAll();
    // after a rollback it is required to dispose of the CMS context
    cmsContext.Dispose();
    // display the error message
    lblErrorMessage.Text = ex.Message;
    }
    }
    }

The code first gets a reference to the posting to be copied followed by the destination channel specified in the txtDestination textbox. The Posting.CopyTo() method accepts the destination channel object as an input parameter. Once the copy has been created, you can proceed to set its properties. The copy operation will only be persisted after a call to CommitAll() is made.

In order to test the Copy Posting dialog, we first create a channel to which to copy the postings:

  1. Navigate to http://localhost/CmsExplorer.

  2. Select New | New Channel.

  3. Name the new channel MyNewChannel2. Click Create Channel and then click Close.

  4. Click MyNewChannel.

  5. Click the Edit button on the row for My New Posting.

  6. Click Copy. This will open a new browser window containing the Copy Posting dialog.

  7. In the Copy Posting dialog, enter /Channels/MyNewChannel2 in the Destination Channel textbox, click Copy Posting, and then click Close.

Notice that a copy of My New Posting is created in MyNewChannel2. The copied posting has the same properties and placeholder content as the original posting with the following exceptions:

  • CreatedBy, LastModifiedBy, and OwnedBy; which hold the server account of the person who executed the copy

  • CreatedDate and LastModifiedDate; which contain the date and time that the copy operation was carried out

After copying, the copied posting’s state is Saved. It has to be approved before it is published.

Other -----------------
- Upgrading to Systems Management Server 2003 - Upgrading a Primary Site & Upgrading a Secondary Site
- Exchange Server 2007 : Securing Access to ActiveSync Using Internet Security and Acceleration (ISA) Server 2006
- Exchange Server 2007 : Working with ActiveSync Policies
- Microsoft Lync Server 2010 Edge : Reverse Proxy Configuration (part 3)
- Microsoft Lync Server 2010 Edge : Reverse Proxy Configuration (part 2)
- Microsoft Lync Server 2010 Edge : Reverse Proxy Configuration (part 1) - Create Web Listener
- InfoPath Designer 2010 : Create an InfoPath 2010 Add-In & Create a Custom Task Pane
- InfoPath Designer 2010 : Access Your Form Within a Visual Studio Workflow
- Microsoft SQL Server 2008 R2 : Query Plan Caching (part 2) - Monitoring the Plan Cache
- Microsoft SQL Server 2008 R2 : Query Plan Caching (part 1) - Query Plan Reuse & Query Plan Aging
 
 
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
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
programming4us programming4us
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
 
programming4us
Natural Miscarriage
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Game Trailer