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 : Moving 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:13:30 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 : Copying Postings
- 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
 
 
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