ENTERPRISE

Microsoft Content Management Server Development : Managing Channels and Postings with the PAPI - Moving Postings

2/25/2011 11:33:42 AM
You can change the parent container of a posting by moving it. Postings can be moved in both the Web Author (using the Move Posting option) and Site Manager (dragging and dropping postings from one channel to another). Once moved, postings require moderator approval if any are assigned for the destination channel.

The PAPI provides the Posting.MoveTo() method to move postings using code. One common application of the method is to automatically approve postings that are moved. When reorganizing large numbers of postings, it is often quicker to write a script to automate the move and to approve them immediately instead of performing these steps manually.

To see how the Posting.MoveTo() method is used within code, we’ll create a Move Posting dialog for CMS Explorer:

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

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

  3. Toggle to HTML view. Add the following code for a table with four rows between the <form> tags.

    <table>
    <tr>
    <td colspan="2">
    <h1>Move 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 Move Posting button here)
    <INPUT type="button" value="Close"
    onclick="javascript:window.close();">
    </td>
    </tr>
    </table>
  4. In Design view, add controls and arrange them as shown in the diagram below:

    ControlProperty PropertyValue
    LiteralIDlitCurrentPosting
    TextBoxIDtxtDestination
    ButtonIDbtnMove
     TextMove Posting
    LabelIDlblErrorMessage
     Text(empty string)

  5. Double-click on the form to get to the code-behind file. As before, import the Microsoft.ContentManagement.Publishing namespace. In the Page_Load() event handler, populate the litCurrentPosting Literal with the path of the posting to be moved.

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

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

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

    #region Web Form Designer generated code
    . . . code continues . . .
    #endregion
    }
    }

  6. Toggle to Design view and double-click on the btnMove button. In the btnMove_Click() event handler, add the following code:

    private void btnMove_Click(object sender, System.EventArgs e)
    {
    CmsHttpContext cmsContext = CmsHttpContext.Current;
    // get the posting to be moved
    Posting 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);
    currentPosting.MoveTo(destination);
    // you can approve the posting
    // or set its properties here
    // e.g. currentPosting.Approve();
    cmsContext.CommitAll();
    // display the success message
    lblErrorMessage.Text = "Posting moved successfully!";
    }
    else
    {
    lblErrorMessage.Text = "Invalid Destination Channel";
    }
    }
    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;
    }
    }
    else
    {
    lblErrorMessage.Text = "Requested posting does not exist.";
    }
    }

The Posting.MoveTo() method accepts the destination channel as an input parameter. In the code above, we use the Searches.GetByPath() method to get the destination channel based on the path entered in the txtDestination textbox. If the channel exists, we pass it in as an input parameter to the Posting.MoveTo() method.

Let’s see the move in action. First, if you haven’t already done so, build the CMSExplorer project, then:

  1. Open http://localhost/CMSExplorer.

  2. Click on MyNewChannel.

  3. Click on the Edit button of the MyPosting posting and click Move.

  4. In the Move Posting dialog, enter /Channels/MyNewChannel2/ as the destination channel. Click Move Posting.

And MyPosting gets moved from MyNewChannel to MyNewChannel2.

Moving postings does not modify any of their placeholder or property values. However, if there are moderators assigned to the destination channel, the posting would be in a “Waiting For Moderator Approval” state. At the same time, the LastModifiedBy and LastModifiedDate properties of the moved posting are modified to indicate the person who executed the move and the date and time that the operation was performed.

Other  
  •  Microsoft Content Management Server Development : Managing Channels and Postings with the PAPI - Copying Postings
  •  Hosting a Multi-Tenant Application on Windows Azure : Selecting a Single-Tenant or Multi-Tenant Architecture
  •  SharePoint 2010 :Implementing a Partner Extranet Solution (part 2) - Configuring Authentication Providers
  •  SharePoint 2010 :Implementing a Partner Extranet Solution (part 1) - Creating the Extranet Web Application & Creating an Extranet Site Collection
  •  SharePoint 2010 : Implementing Authentication Scenarios
  •  Designing and Configuring Unified Messaging in Exchange Server 2010 : Unified Messaging Installation (part 3)
  •  Designing and Configuring Unified Messaging in Exchange Server 2010 : Unified Messaging Installation (part 2)
  •  Designing and Configuring Unified Messaging in Exchange Server 2010 : Unified Messaging Installation (part 1)
  •  Hosting a Multi-Tenant Application on Windows Azure : Single-Tenant vs. Multi-Tenant & Multi-Tenancy Architecture in Azure
  •  Understanding SharePoint 2010 Extranet Security
  •  Sharepoint 2010 : Outlining Common Extranet Scenarios and Topologies
  •  Sharepoint 2010 : Virtual Machine Management with System Center Virtual Machine Manager
  •  Designing and Configuring Unified Messaging in Exchange Server 2010 : Unified Messaging Architecture (part 3)
  •  Designing and Configuring Unified Messaging in Exchange Server 2010 : Unified Messaging Architecture (part 2)
  •  Designing and Configuring Unified Messaging in Exchange Server 2010 : Unified Messaging Architecture (part 1)
  •  Designing and Configuring Unified Messaging in Exchange Server 2010 : Unified Messaging Features
  •  Exploring Sample Virtualized SharePoint 2010 Architecture
  •  Virtualizing SharePoint Components : Virtualization of SharePoint Roles
  •  Monitoring a SharePoint 2010 Environment : Establishing Maintenance Schedules for SharePoint
  •  Using System Center Operations Manager to Simplify Management of SharePoint 2010
  •  
    Top 10
    -  Nikon 1 J2 With Stylish Design And Dependable Image And Video Quality
    -  Canon Powershot D20 - Super-Durable Waterproof Camera
    -  Fujifilm Finepix F800EXR – Another Excellent EXR
    -  Sony NEX-6 – The Best Compact Camera
    -  Teufel Cubycon 2 – An Excellent All-In-One For Films
    -  Dell S2740L - A Beautifully Crafted 27-inch IPS Monitor
    -  Philips 55PFL6007T With Fantastic Picture Quality
    -  Philips Gioco 278G4 – An Excellent 27-inch Screen
    -  Sony VPL-HW50ES – Sony’s Best Home Cinema Projector
    -  Windows Vista : Installing and Running Applications - Launching Applications
    Most View
    -  Bamboo Splash - Powerful Specs And Friendly Interface
    -  Powered By Windows (Part 2) - Toshiba Satellite U840 Series, Philips E248C3 MODA Lightframe Monitor & HP Envy Spectre 14
    -  MSI X79A-GD65 8D - Power without the Cost
    -  Canon EOS M With Wonderful Touchscreen Interface (Part 1)
    -  Windows Server 2003 : Building an Active Directory Structure (part 1) - The First Domain
    -  Personalize Your iPhone Case
    -  Speed ​​up browsing with a faster DNS
    -  Using and Configuring Public Folder Sharing
    -  Extending the Real-Time Communications Functionality of Exchange Server 2007 : Installing OCS 2007 (part 1)
    -  Google, privacy & you (Part 1)
    -  iPhone Application Development : Making Multivalue Choices with Pickers - Understanding Pickers
    -  Microsoft Surface With Windows RT - Truly A Unique Tablet
    -  Network Configuration & Troubleshooting (Part 1)
    -  Panasonic Lumix GH3 – The Fastest Touchscreen-Camera (Part 2)
    -  Programming Microsoft SQL Server 2005 : FOR XML Commands (part 3) - OPENXML Enhancements in SQL Server 2005
    -  Exchange Server 2010 : Track Exchange Performance (part 2) - Test the Performance Limitations in a Lab
    -  Extra Network Hardware Round-Up (Part 2) - NAS Drives, Media Center Extenders & Games Consoles
    -  Windows Server 2003 : Planning a Host Name Resolution Strategy - Understanding Name Resolution Requirements
    -  Google’s Data Liberation Front (Part 2)
    -  Datacolor SpyderLensCal (Part 1)