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

InfoPath with Microsoft Content Management Server Web Services : Creating the Business Layer (part 4) - Maintaining Placeholder Collections

7/12/2012 5:49:15 PM

Maintaining Placeholder Collections

Let’s now create a collection class to hold LightweightPlaceholders that we’ll call LightweightPlaceholderCollection. The LightweightPlaceholderCollection will be used as postings may have more than one placeholder defined.

1.
In Visual Studio .NET, create a new class, LightweightPlaceholderCollection, and add the MCMS Publishing and Placeholders namespaces to it. Also change the class to extend System.Collections.CollectionBase:

using System;
using Microsoft.ContentManagement.Publishing;
using Microsoft.ContentManagement.Publishing.Extensions.Placeholders;
namespace McmsAuthoringWebService
{
  /// <summary>
  /// Summary description for LightweightPlaceholderCollection.
  /// </summary>
  public class LightweightPlaceholderCollection
                  : System.Collections.CollectionBase
  {
    . . . code continues . . .
  }
}

					  

2.
As LightweightPlaceholderCollection is a strongly typed collection, the default property will be a LightweightPlaceholder:

/// <summary>
/// The indexed LightweightPlaceholder
/// </summary>
public LightweightPlaceholder this[int index]
{
  get
  {
    // Cast the list item to a LightweightPlaceholder
    return(this.InnerList[index] as LightweightPlaceholder);
  }
  set
  {
    this.InnerList[index] = value;
  }
}

3.
We now define the Add() method that will add a LightweightPlaceholder to the collection:

/// <summary>
/// Add an item to the collection
/// </summary>
/// <param name="item">The LightweightPlaceholder to be added</param>
public void Add(LightweightPlaceholder item)
{
  this.InnerList.Add(item);
}

4.
The LightweightPlaceholderCollection will be populated by loading a Microsoft.ContentManagement.Publishing.Posting object, so let’s create the Load() method.

For the purposes of this example we are only maintaining placeholders of type HtmlPlaceholder. The code could be easily extended to maintain different types of placeholders.


/// <summary>
/// Load the lightweight Placeholder collection from a posting.
/// </summary>
/// <param name="_Posting">Posting to be loaded from</param>
public void Load(Posting _Posting)
{
  if (_Posting != null)
  {
    // Loop through the Placeholders
    foreach (Placeholder _Placeholder in _Posting.Placeholders)
     {
      // Check if the custom Placeholder is an HtmlPlaceholder
      if (_Placeholder is HtmlPlaceholder)
       {
        // Instantiate a lightweight Placeholder and
        // add it to the collection
        this.Add(new LightweightPlaceholder(_Placeholder));
       }
     }
  }
}

5.
To save the content of all the placeholders in the collection, we will create a Save() method that iterates through all the placeholders and calls Save() for each:

/// <summary>
/// Save the collection of placeholders
/// </summary>
/// <param name="_Posting">Posting to save the placeholder values to</param>
public void Save(Posting _Posting)
{

  // Loop the Placeholders in the collection
  foreach (LightweightPlaceholder _LightweightPlaceholder in this)
  {

    // Save the Placeholder against the posting
    _LightweightPlaceholder.Save(_Posting);

  }
}

					  

Now we have defined our classes for maintaining custom properties and placeholders, and for storing template definition data, the McmsAuthoringWebService project should look as in the figure overleaf:

Other -----------------
- InfoPath with Microsoft Content Management Server Web Services : Creating the MCMS Web Service Project
- Microsoft SharePoint 2010 : Social Architecture - Viewing an Activity feed, Setting up and compiling an audience
- Microsoft SharePoint 2010 : Creating an Alternate Access Mapping & Patching
- Microsoft Systems Management Server 2003 : Communicating Through Senders (part 2) - Courier Sender
- Microsoft Systems Management Server 2003 : Communicating Through Senders (part 1) - Sender Process Flow & Defining a Sender
- Windows Server 2008 Server Core : Working with iSCSI Using the iSCSICli Utility (part 2) - iSCSICli Mappings and Flags
- Windows Server 2008 Server Core : Working with iSCSI Using the iSCSICli Utility (part 1) - Working with the iSCSI Client (iSCSICli) Utility
- Active Directory Domain Services 2008 : Modify an Organizational Unit's General Properties, Modify an Organizational Unit's Managed By Properties
- Active Directory Domain Services 2008 : Move an Organizational Unit
- Windows Server 2008 R2 : Troubleshoot IPV4 - Verify Responsiveness
 
 
Video tutorials
- How To Install Windows 8

- How To Install Windows Server 2012

- How To Install Windows Server 2012 On VirtualBox

- How To Disable Windows 8 Metro UI

- How To Install Windows Store Apps From Windows 8 Classic Desktop

- How To Disable Windows Update in Windows 8

- How To Disable Windows 8 Metro UI

- How To Add Widgets To Windows 8 Lock Screen

- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010
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
 
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
 
programming4us
Women
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone