MCMS MOSS Content Sharing Placeholder
While I was examining Olivier Carpentier's WSS List DataSource on http://www.codeplex.com I decided to try and create a similar tool for MCMS. The basic idea was to create a custom placeholder which allows content editors to select WSS lists from a remote MOSS server.
But first, a few words on MCMAS custom placeholders:
A Placeholder is a control which has 2 major instances – one for users where it displays the content and one for the content editor so they can alter the content.
Creating a custom placeholder is quite simple actually:
1. Create a class
2. Inherit from BasePlaceholderControl
3. Override the 5 required methods
4. Implement the methods.
The 5 methods are:
protected override void CreateAuthoringChildControls(BaseModeContainer authoringContainer)
{
//Create controls for the editors view
}
protected override void CreatePresentationChildControls(
BaseModeContainer presentationContainer)
{
//Create controls for the users view
}
protected override void LoadPlaceholderContentForAuthoring(
PlaceholderControlEventArgs e)
{
//Load content for the editors
}
protected override void LoadPlaceholderContentForPresentation(
PlaceholderControlEventArgs e)
{
//Load content for the users
}
protected override void SavePlaceholderContent(
PlaceholderControlSaveEventArgs e)
{
//Save the content
}
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
More information on creating custom placeholders can be found at How to: Create Custom Placeholder Controls.
This particular placeholder needs 4 different components in order perform:
1. MCMS Custom placeholder who displays the editors UI and also exposes the retrieved data to other elements on the page.
2. Editors list selection UI based on an ActiveX
3. MOSS Web services
4. Source downloader using Http Module.
All 4 are required in order to be able to point a list, get the data and also download items such as files / images from the list itself.
MCMS Custom placeholder
Since I wanted my placeholder to function as a data source I also implemented the IDataSource interface in order to expose the retrieved data from MOSS.
My class declaration looks like this:
public class SPSListSelector : BasePlaceholderControl, IDataSource, INamingContainer
{
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
User mode (Presentation)
The control displays nothing to the user.
Editor mode (Authoring)
The control displays a button (Image) to the editor. Clicking the button opens the ActiveX UI as a windows form, this is achieved using JavaScript.
More information about .NET ActiveX and ASP.NET applications can be found at writing an ActiveX control in C#.
The control has 4 main properties:
1. Text message which will be displayed as a tooltip from the button
2. User name to use for the remote access
3. Password to use for the remote access
4. Domain to use for the remote access
Editors list selection UI
The UI is a simple windows form which allows the editor to select lists, views and fields from a remote MOSS server:
Unlike Oliver's control my control only lets the editor to set a simple where condition, maybe I'll implement a more complexes version in the future.
All communications from the UI to the remote server are done using MOSS web services located on the server by default so there is no change needed on the server at all. (The web services has to be accessible in order to allow the component to perform)
MOSS Web services
The information needed for the placeholder came from 3 MOSS web services
1. /_vti_bin/lists.asmx for retrieving information regarding lists
2. /_vti_bin/views.asmx for retrieving information regarding views
3. /_vti_bin/sitedata.asmx for getting the webid needed for querying the content of the lists. (for more information read How to use the GetListItems web service? from Ishai Sagi)
Source downloader
I wrote a simply http module which uses the WebClient object in order to retrieve content from the remote server and send them back to the user as if they were originated from the MCMS server. (for cases where the MOSS is located internally and can't be accessed by the users of the external web site.
Using the placeholder
Inside visual studio the use of the placeholder is similar to any other custom placeholder.
After dragging the control from the toolbox it has to be attached to a placeholder definition (XML placeholder definition) and get the MOSS credential through its properties:
After all that is done it is possible to use the placeholder just as every other data source, for example – attaching a grid view control to it:
That is all – after choosing a list / view / fields the grid view will display the retrieved data. Since the control also returns a formatted URL for downloading files the grid view can even show images from MOSS as if they were located on the MCMS server:
I will publish the source code on codeplex.com sometime soon after a short testing period :)