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

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

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
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
 
 
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
 
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server