Advanced Microsoft Content Management Server Development
Advanced Microsoft Content Management Server Development
Working with the Publishing API, Placeholders, Search,
Web Services, RSS, and SharePoint Integration Lim Mei Ying Stefan Goßner Angus Logan Andrew Connell BIRMINGHAM - MUMBAIAdvanced Microsoft Content Management Server Development Working with the Publishing API, Placeholders, Search, Web Services, RSS, and SharePoint Integration Copyright © 2005 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the
information presented. However, the information contained in this book is sold without warranty,
either express or implied. Neither the authors, Packt Publishing, nor its dealers or distributors will
be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all the companies and
products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.First edition: November 2005 Published by Packt Publishing Ltd.
32 Lincoln Road Olton Birmingham, B27 6PA, UK.
ISBN 1-904811-53-1
www. pac k t pub. c om
Cover Design by www. v i s i onwt . c om FM-2
FM-3 Credits
Authors Lim Mei Ying Stefan Goßner Angus Logan Andrew Connell Technical Reviewers Mick Badran Spencer Harbar David Mielcarek Chester Ragel Christopher Walker Joel Ward Editorial Manager Dipali Chittar
Development Editor Douglas Paterson Technical Editor Richard Deeson Indexer Niranjan Jahagirdar
Proofreader
Chris Smith Production Coordinator Manjiri Nadkarni Cover Designer
Helen Wood About the Authors
Lim Mei Ying is a Senior Consultant with Avanade and has extensive experience in setting up
MCMS systems at the enterprise level. She has spent many hours figuring out the dos and don'ts of the product, and enjoys finding new ways to solve MCMS-related problems. She contributes actively to the newsgroup community and is a Microsoft Most Valuable Professional for Content Management Server. Mei Ying lives on the sunny island of Singaporeht t p: / / mei y i ngl i m. bl ogs pot . c om
and blogs at . She also co-authored the earlier book, Building Websites with Microsoft Content Management Server (ISBN: 1-904811-16-7, Packt Publishing January 2005).
Thanks to my husband, Louis, for the much needed support throughout the many months
of writing. Special thanks to my family and friends for their encouragement. works for Microsoft as an Escalation Engineer in the Developer SupportStefan Goßner department. He provides customers with technical solutions to problems related to Microsoft Internet Server Products. Stefan has a broad and deep understanding of all areas of MCMS. His
contributions to the newsgroup community have helped many people implement MCMS solutions
in corporations around the globe, to the point where it has been said that if you don't know Stefan,
then you're probably new to MCMS.He maintains a huge MCMS 2002 FAQ on the Microsoft website and provides MCMS tips and tricks on his personal blog at ht t p: / / bl ogs . t ec hnet . c om/ s t ef an_gos s ner . He lives in Munich, Germany.
I would like to thank my girlfriend, Michaela, for her support throughout months of writing, reviewing, and coding for the book. Also many thanks to my colleagues in the European Developer Support Team and to my friends in the MCMS product team in the US.
ht t p: / / www. dat a3. c om. au
Angus Logan is a Product Specialist at Data#3 Limited ( ), Australia's leading IT solutions company, and is a Microsoft Gold Certified Partner. Angus is a MCAD.NET and MCDBA, as well as a Microsoft Most Valuable Professional for Content Management Server. His specialities are Content Management Server, SharePoint Portal Server, .NET development, SQL Server, and Customer Relationship Management (CRM).
mi c r os of t . *
You can usually find Angus in the newsgroups or blogging ( ht t p: / / www. angus l ogan. c om ).
FM-4
Angus gets a real buzz from using these technologies in a presales or delivery capacity to find solutions to his customers' real-world problems.
To my friends and family, especially Michael, thank you! Working with a great team on this
book made all the time and effort worthwhile.
Andrew Connell has worked with content-management solutions since obtaining his degree
from the University of Florida. As one of the original developers for the most successful versions
of AdmiNET, a custom web content administration product, he has consistently focused on thechallenges facing businesses today as they strive to maintain an up-to-date site without having to
constantly rely on technical expertise.
Andrew's background is in content-management solutions and web development using Microsoft
technologies. He enjoys working with MCMS and integrating it with other products such as Microsoft SharePoint Products and Technologies. As a Client/Server Consultant for Fidelity Information Services, Andrew has leveraged both MCMS and SharePoint Portal Server to redeploy Fidelity's intranet site as a single solution thatcapitalizes on the best features of both products. In 2005, he was recognized as a Microsoft Most
Valuable Professional for his contributions to the MCMS community.Andrew lives in Jacksonville, Florida in the United States, and maintains a blog at
ht t p: / / www. andr ewc onnel l . c om/ .
Thank you to my wife, Meredith, and first born son, Steven, for their patience and support.
Thanks to my girls Maggie and Sadie for providing me company during the many latenights it took to finish this project. Thanks also to my parents and brother for their support
and the confidence they showed in me.Shared Acknowledgements We the authors would also like to thank the following people for supporting us and helping us along the way:
Our editors, Douglas Paterson and Richard Deeson, and the rest of the team at Packt for accepting
our book proposal and for the wonderful work they have done in bringing this book to life.
Our project manager, Joel Ward, for his exceptional project management skills. Thanks for being
there for us! FM-5About the Reviewers
Mick Badran has been performing Microsoft technical classroom-based training for more than
nine years, and has over 12 years commercial development experience in various languages. Mick
has been consulting for Microsoft in areas of CMS, SPS, and BizTalk for over four years. Mick also specializes in customized training in these areas. He can be reached at mi c k b@br eez et r ai ni ng. c om. au and would love to hear your feedback. is an MCSD.NET, MCSE, and MVP for MCMS, with over ten yearsSpencer Harbar
commercial experience of architecture, design, development, deployment, and operational support
of web-based applications, and hosting platforms for some of Europe's largest organizations.Spencer maintains ht t p: / / www. mc ms f aq. c om —an MCMS resources portal—and is active in the
public newsgroups. His experience of MCMS goes back to the days of NCompass Resolution, and
he has been involved in many enterprise implementations. Selected clients include Barclays Bank plc, ScottishPower plc, Microsoft, The Royal Bank of Scotland, Scottish Enterprise, HBOS, Centrica, BASF, and The Automobile Association. Currently working as an independent consultant, Spencer delivers enterprise content management and portal systems architecture, design, development, and deployment solutions, application security best practices, threat modeling, and the implementation of highly available Windows Server System-based hosting platforms.Spencer resides in Edinburgh, UK, and blogs at www. har bar . net . is employed as the Internet/Domain Administrator at Lower Columbia
David Mielcarek College in Washington State. Most of the time, he utilizes one of ten programming languages to get the job done.
Starting his career as a telecommunications cryptologist in the Air Force, he merged into the corporate world. Following a term with Lockheed, he increased his abilities by taking on larger positions. In 1994, the Internet became his mainstay, and it remains so to this day. Juggling an educational position, outside-work through his GoldBorder.com site, and raising a
family of three kids, 11 cats, two dogs, and two rats allows little time for his love of drawing. You
can often find him taking his short breaks at the nearest table to pencil something in his art pad.FM-6
Chester Ragel is a Computer Professional, obtaining his degree in Computer Science and
Engineering from the University of Moratuwa. He is an MCSD.NET holder, and enjoys working
with Microsoft technologies.
Chester contributes to the MCMS community and several IT Magazines. He lives in Sri Lanka and
can be found blogging at ht t p: / / c hes t er mr . bl ogs pot . c om .Christopher Walker is a Senior Consultant with Microsoft Services, providing specialist
advice on integrated portal solutions (SharePoint, MCMS, BizTalk, and InfoPath). Christopher has
a background in portal development and technologies with Unisys and a portal software ISV.ht t p: / / bl ogs. msdn. com/ cj wal ker /
Christopher contributes to the community through his blog at ,
providing real solutions to customers using Microsoft technologies. Christopher lives in Brisbane, Australia.
Joel Ward works for Booz Allen Hamilton as a technical manager and developer. Joel likes to
work on ASP.NET, MCMS, and SharePoint projects, and he helped create a .NET user group atBooz Allen. He has a background in design, programming, and architecture, and has worked with
MCMS since its first release in 2001.
As a Microsoft Most Valuable Professional, Joel is acknowledged by peers and Microsoft for his
active participation in the technical communities around the globe. Joel lives in Virginia in the United States.FM-7
Table of Contents
Table of Contents
ii
Table of Contents
iii Table of Contents
iv
Table of Contents
v
Table of Contents
Chapter 9: Validating Placeholder Controls 285 Limitations of the ASP.NET Validation Controls 285 The MCMSValidators Project
vi
Table of Contents
vii Table of Contents
viii Table of Contents
Chapter 13: Essential How-Tos, Tips, and Tricks 413 Tip #1: How to Revert a Posting to a Previous Version 414 The Revert Page to Previous Version Dialog 414 How to Get and Sort a List of Page Revisions 418 Programming the Button that Triggers the Page Reversion Process 419 Copying Content from One Placeholder to Another 422 Copying Custom Property Values
ix Table of Contents
x
Table of Contents
xi
Introduction Following on from Building Websites with Microsoft Content Management Server (Packt
Publishing, January 2005, ISBN 1-904811-16-7), this book takes MCMS development to a higher
level of both power and integration. Like its predecessor, this book is packed with code examples and never-before-seen secrets of MCMS. Microsoft Content Management Server 2002 is a dynamic web publishing system with which you can build websites quickly and cost-efficiently. MCMS provides the administration, authoring, and data-management functionality and you provide the website interface, logic, and workflow.Microsoft SharePoint Portal Server (SPS) also features in this book. SPS 2003 enables enterprises to
deploy an intelligent portal that seamlessly connects users, teams, and knowledge so that people cantake advantage of relevant information across business processes to help them work more efficiently.
You've mastered the basics of MCMS, and have set up your own MCMS installation. But you've only scratched the surface. This book is your gateway to squeezing every penny from your investment in MCMS and SPS, and making these two applications work together to provide an outstanding richness of content delivery and easy maintainability.What This Book Covers
Chapter 1 demonstrates the power of the MCMS Publishing API (PAPI) by building the CMS
Explorer administration tool to manage an MCMS website. Chapter 2 builds on the CMS Explorer by adding the ability to manage channels and postings. Chapter 3 looks at the creation,
submission, copying, moving, and deletion of templates, template galleries, and resources through
the PAPI.In Chapter 4, you will learn how to prepare postings for search indexing. We look at several techniques that can improve the accuracy of search results and optimize your search engine. SharePoint Portal Technologies complement MCMS by providing collaboration, document
libraries, and searching to the robust publishing workflow of MCMS. Chapter 5 takes you through
the process of adding searching to an MCMS Site using SharePoint Portal Server, either using the
MCMS Connector for SharePoint Technologies or by building your own solution.Chapter 6 demonstrates how you can use the MCMS Connector for SharePoint to build your own
components to share content between MCMS and SharePoint. Chapter 7 shows how you can build
Web Parts that integrate content from MCMS on a SharePoint portal site.Chapter 8
discusses five custom placeholder controls that provide some frequently requested
features that are not present in the default controls: a date-time picker placeholder control, a placeholder control that permits multiple attachments, an image-rotator placeholder control, a placeholder control to store all kinds of HTML tags, and a DataGrid placeholder control.Introduction
Validation of content is a key requirement in many MCMS implementations. Chapter 9 looks at how
you can apply ASP.NET validation techniques to each of the out-of-the box placeholder controls.Static pages are often used in direct mailers, help files, and even for archiving purposes. Chapter
10 discusses a couple of techniques that you can use to create static snapshots of postings.
The authoring experience doesn't always need to be through the browser. One author-friendly way
of maintaining content is detailed in Chapter 11. In this chapter, we leverage the power of InfoPath to quickly create a GUI that allows authors to submit content directly from Microsoft Word, with the help of MCMS Web Services.
Since the release of MCMS in 2002, a lot of technologies have changed. Syndication of websites
using RSS is the norm, and to capitalize on this, Chapter 12 takes you through the steps involved
in creating a dynamic RSS feed of your website's recent changes. Finally, Chapter 13 provides many invaluable insider's tips and tricks for MCMS, as well assolutions to common MCMS issues, including gems such as how to revert a posting to a previous
version, change a posting's template, build a recycle bin, and export resource gallery items using
the Site Deployment API.What You Need for This Book
This book has been written for ASP.NET developers with a sound grasp of C#. To use this book,
you need to have access to the following:- Visual Studio .NET Professional or higher (2002 or 2003 version).
- Microsoft Content Management Server 2002 Developer or Enterprise edition.
You can also use the Standard edition, but be aware that some features will not be
available. A 120-day evaluation version of the Enterprise edition is available at
ht t p: / / www. mi c r os of t . c om/ c ms er v er .
To install and run Microsoft Content Management Server 2002, you will need the following: • The .NET Framework 1.0 or 1.1.
- One of the following operating systems: Windows Server 2003, Windows 2000 Professional, Windows 2000 Server, or Windows XP Professional.
- An installation of SQL Server 2000 Developer or Enterprise edition.
Some of the chapters utilize Microsoft SharePoint Portal Server 2003. For these chapters, you
will need: • The .NET Framework 1.1. - Windows Server 2003.
- An installation of SQL Server 2000 Developer or Enterprise editions.
- An installation of SharePoint Portal Server 2003. A 120-day evaluation version is available at ht t p: / / www. mi c r os of t . c om/ s har epoi nt .
2
Introduction
Conventions In this book, you will find a number of styles of text that distinguish between different kinds of information. This section provides some examples of these styles, and an explanation of their meaning.
There are three styles for code. Code words in text are shown as follows: "Pass the path of any object
as an input parameter of the Sear ches. Get ByPat h( ) method to retrieve the requested object".If we have a block of code, it will be set as follows:
Hi er ar c hy I t em hI t em = c ms Cont ex t . Sear c hes . Get By Pat h( " / Channel s / Tr opi c al Gr een/ My s t er y Obj ec t " ) ; i f ( hI t em i s Channel ) { / / Obj ec t i s a Channel } el s e i f ( hI t em i s Pos t i ng) { / / Obj ec t i s a Pos t i ng }
When we wish to draw your attention to a particular part of a code block, the relevant lines will be
made bold:pr i v at e Cms Ht t pCont ex t c ms Cont ex t ; pr i v at e v oi d Page_Load( obj ec t s ender , Sy s t em. Ev ent Ar gs e) { / / Put us er c ode t o i ni t i al i z e t he page her e c ms Cont ex t = Cms Ht t pCont ex t . Cur r ent ; i f ( ! Page. I s Pos t Bac k ) { Get Pl ant Fac t Sheet s ( ) ; } }
New terms and important words are introduced in a bold-type font. Words that you see on the Next
screen, in menus, on dialog boxes, and so on, appear in our text like this: "clicking the button
takes you to the next screen".General tips, suggestions, or important notes appear in a box like this. Troubleshooting tips and suggestions appear in the following format: The option for the component I want to install is grayed out and I can't select it.
That's because you do not have the prerequisites required by that component. For
example, if you did not install Microsoft Visual Studio, you will not be able to install the
Developer Tools. To find out what's missing, click on the component and read the description on the right-hand side of the dialog.3 Introduction
Any command-line input and output is written as follows:
s n –k " c : \ Tr opi c al Gr eenGACKey \ Tr opi c al Gr eenKey . s nk "
Reader Feedback
Feedback from our readers is always welcome. Let us know what you think about this book, what
you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.To send us general feedback, simply drop an e-mail to f eedbac k @pac k t pub. c om , making sure to
mention the book title in the subject of your message.
If there is a book that you need and would like to see us publish, then please send us a note in the
SUGGEST A TITLE www. pac k t pub. c om s ugges t @pac k t pub. c om form on or e-mail .
If there is a topic that you have expertise in and you are interested in either writing or contributing
www. pac k t pub. c om/ aut hor s to a book, then see our author guide on .
Customer Support Now that you are the proud owner of a Packt book, we want you to get the most from your purchase. Packt's Customer Support is here to try to make sure that happens, and there are a number of ways we can help you.
Downloading the Example Code for the Book
Visit ht t p: / / www. pac k t pub. c om/ s uppor t , and select this book from the list of titles to view any
example code or extra resources available for download for this book.The downloadable files contain instructions on how to use them.
Errata Although we have taken every care to ensure the accuracy of our books' contents, mistakes do happen. If you find a mistake in one of our books—be it a mistake in text or a code error—we would be grateful if you could report this to us. By doing this you can save other readers from frustration, and also help to improve subsequent versions of this book.
To report any errata you find, visit ht t p: / / www. pac k t pub. c om/ s uppor t , select your book, click
on the Submit Errata link, and enter the details of your errata. Once your errata have been verified,
your submission will be accepted and added to the list of existing errata. The existing errata can be
ht t p: / / www. pac k t pub. c om/ s uppor t viewed by selecting your title from .
Questions
ques t i ons @pac k t pub. c om
You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.
4
1 Building CMS Explorer The Building Websites with Microsoft Content Management Server book (Packt Publishing, January 2005, ISBN 1-904811-16-7) makes extensive use of MCMS's Publishing Application Programming Interface (PAPI). We show how to use it to provide custom functionality within template files, to add business processes to workflow events, to tailor the Web Author Console, and to implement forms authentication for the Tropical Green site, which the reader builds as they progress through the book. The PAPI is in fact a huge library. You could code with it for months and still find new tricks you never knew existed! This is the first of three chapters that compliment the understanding you will have gained from the book and attempt to take your understanding of the PAPI to another level. Follow along as we demonstrate several highly useful techniques and show how they can be leveraged in a real-world scenario, as we apply them to the Tropical Green site.
Where can I download a copy of the Tropical Green website? The code files for the Tropical Green website created over the course of the earlier book are available as a download package on this book's download page. Go to the Packt website at
ht t p: / / www. packt pub. com/ suppor t / Advanced Microsoft Content
, and choose Management Server Development in the dropdown.
A Central Administrative Tool: CMS Explorer We put some serious thought into creating an example that would not only give you a thorough grounding in the more advanced methods available in the PAPI but would also leave you with a tool that you will find handy in your day-to-day MCMS work. From our own experiences as MCMS developers working in the time-critical world of the software industry, one thing that we have found invaluable has been a custom MCMS administrative tool. In the first three chapters of this book, we walk you through the process of building such a tool, which we will name CMS Explorer.
Building CMS Explorer
The interface is made up of two sections:
• At the top of the page (in case you hadn't guessed, we're going to create the tool as a
web application), you'll see a toolbar. The toolbar provides a drop-down list with
options to create new postings and channels. It also has three buttons: one to toggleto a list of channels and postings, a second to list template galleries and templates,
and a third for resource galleries and resources.- The second half of the page is a
Dat aGr i d . The grid lists the items in the current
container. Each row has an Edit button, which reveals a list of actions for each object when clicked.
For navigation, you can move in two directions: click on the name of the container to see what's in
it, or use the Up button on the toolbar to move up one level. Why build a tool when the out-of-the box-solution provides not one, but three tools to manage MCMS objects? There's already a Site Manager and the Web Author as well as the Template Explorer available within Visual Studio .NET. There are several reasons why building the CMS Explorer tool is worthwhile:- Firstly of course, you'll get first-hand experience in using many of the more advanced methods from the PAPI. After building this tool, you will not only be very
comfortable with the PAPI but also well on your way to becoming an expert in it!
- Although the PAPI contains a large collection of classes, it doesn't cover everything. While it would be nice for the CMS Explorer to be able to do
everything that the tools shipped with MCMS can do, it can't go beyond what's
available in the PAPI. One of the secondary objectives of the next few chapters is to highlight the PAPI's limitations.
6 Here's how CMS Explorer will look once completed:
- Finally, this tool could quite likely be useful in your daily work. There are some actions that can only be done using Site Manager, some that are available only within
Web Author, and others exclusive to Template Explorer. For example, you would
use Site Manager to create a channel and switch over to Web Author to create
postings within it. CMS Explorer attempts to fill in this gap by providing as much
functionality as possible from a single location.
Properties .
Literal control to
display the name of the current container. The l bl Publ i s hi ngMode Label will be
used later to display the current publishing mode.l i t Cur r ent Cont ai ner
8. Switch to HTML view. Add the table below between the <f or m> tags to provide the
basic structure of the page. We use a
7. In Design view, drag and drop the St y l es . c s s file from Solution Explorer onto the
form. This applies the stylesheet to the page.def aul t . as px .
6. Add a new web form to the CMSExplorer project, and name it
5. Right-click the Console folder and select Delete .
Click Designer Defaults . Set the Page Layout field to Flow . This will set the default layout to flow instead of grid for all web forms created in the project. Click OK .
4. Right-click the CMSExplorer project in the Solution Explorer and select
Chapter 1
3. Create a new folder and name it i mages . Download the image files for this tutorial
from the code download section of the book's companion website and add them to
the project.
2. Get the St y l es . c s s file from the book's code download. Select Project | Add Existing
Item and add it to the CMSExplorer project.CMSEx pl or er .
1. Name the new project
Creating the Workspace Let's start by creating a work area for the CMS Explorer tool. Create a new Visual C# MCMS Web Application Project in Visual Studio .NET.
ht t p: / / www. packt pub. com/ suppor t / .
You can download the entire sample from the code download section of the Packt site, at
7
<t abl e c el l Spac i ng=" 0" c el l Paddi ng=" 0" > <t r > <t d> <t abl e> <t r > <t d v al i gn=" t op" > <as p: I mage r unat =" s er v er " I D=" i mgTi t l e" ></ as p: I mage> </ t d> <t d v al i gn=" c ent er " > <h1> <as p: Li t er al I D=" l i t Cur r ent Cont ai ner " r unat =" s er v er " / > </ h1> </ t d> </ t r > </ t abl e> Building CMS Explorer <as p: Label I D=" l bl Publ i s hi ngMode" r unat =" s er v er " Cs s Cl as s =" Body Tex t " / > </ t d> </ t r > <t r > <t d wi dt h=" 100%" bgc ol or =" #c c c c c c " >( Spac e f or Tool bar ) </ t d> </ t r > <t r > <t d>( Spac e f or Dat aGr i d) </ t d> </ t r > </ t abl e> 9. Toggle to Design view. Double-click on the form to get to its code-behind file.
Above the namespace declaration, import the Mi c r os of t . Cont ent Management . Publ i s hi ng namespace.
/ / MCMS PAPI us i ng Mi c r os of t . Cont ent Management . Publ i s hi ng; names pac e CMSEx pl or er { / / / <s ummar y > / / / Summar y des c r i pt i on f or _def aul t . / / / </ s ummar y > publ i c c l as s _def aul t : Sy s t em. Web. UI . Page { . . . c ode c ont i nues . . . } }
The Four MCMS Publishing Modes MCMS uses four different publishing modes:
- Published: Mode used for displaying a live version of the site
- Staging: Mode used for staging the site using Site Stager
• Unpublished: Mode used for displaying an unpublished version of the site (e.g. in
edit site mode or in preview screens) - Update: Mode used for updating the site (e.g. on the authoring screen with placeholder controls in authoring mode)
Determining the Current Publishing Mode
Cms Ht t pCont ex t . Mode
The current mode can be found using the property. Let's find out which
mode CMS Explorer is currently using.Page_Load( )
Above the event handler in the code-behind file, add the following line:
/ / t he c ur r ent Cms Ht t pCont ex t pr i v at e Cms Ht t pCont ex t c ms Cont ex t ; Page_Load( )
Inside the event, add the following code:
pr i v at e v oi d Page_Load( obj ec t s ender , Sy s t em. Ev ent Ar gs e) { c ms Cont ex t = Cms Ht t pCont ex t . Cur r ent ;
8
Chapter 1 i f ( ! Page. I s Pos t Bac k ) { / / di s pl ay t he publ i s hi ng mode l bl Publ i s hi ngMode. Tex t = " Publ i s hi ng Mode: "
- c ms Cont ex t . Mode. ToSt r i ng( ) ; } } ht t p: / / l oc al hos t / CMSEx pl or er / def aul t . as px
Save and build the solution. Navigate to . Notice
Publishing Mode: Publishedthat the label says . When you first view a web page on an MCMS site,
you are shown the site in its Published mode. You can ignore the broken image for now as we'll address that further along.Publ i s hed
In mode, you only have access to channels and postings that have live versions and that
are not marked as hidden. Channels that have expired or have their start dates set to a future date
will not be available. Postings that have never been published before or are in a "Waiting For Moderator Approval", "Waiting For Editor Approval", "Submitted", "Approved" or "Expired"state will also not be accessible. Obviously, for CMS Explorer to be useable, it's got to be able to
see all objects regardless of their states. In order to work with unpublished objects, we have toPubl i s hed Unpubl i s hed
change the current publishing mode from to , and we look at ways to accomplish this in the following sections.
Changing the MCMS Publishing Mode There are various ways to change the MCMS publishing mode, such as by modifying the
Cms Ht t pCont ex t
querystring parameters in the URL or by manipulating the modes via and
Cms Appl i c at i onCont ex t . Let's take a look at each of these methods.
The Ugly URL Querystring Specifies the Publishing Mode Let's try a little experiment.
ht t p: / / l oc al hos t / t r opi c al gr een 1. Open your browser and navigate to the site.
Switch to Edit Site
2. Log in as an administrator. Click on the button and observe the
URL displayed in the browser's address bar. It changes from a friendly URL to an
ugly long URL containing the familiar querystring parameters at its tail end:ht t p: / / l oc al hos t / NR/ ex er es / 71EDAD1D- 9D58- 4D65- 8069- 19DFC0114F54. ht m? NRMODE=Unpubl i s hed &WBCMODE=Pr es ent at i onUnpubl i s hed &wbc _pur pos e=Bas i c
At the same time, the Switch To Edit Site button disappears and a Switch To Live Site button appears in its place.
Unpubl i s hed
Now, let's make a few changes to the querystring. With the page open in mode:
NRMODE Unpubl i s hed
1. Change the querystring parameter of the ugly URL from
Publ i s hed to .
WBCMODE 2. Delete the querystring parameter.
3. The URL at the address bar now looks something like this:
ht t p: / / l oc al hos t / NR/ ex er es / 71EDAD1D- 9D58- 4D65- 8069- 19DFC0114F54. ht m? NRMODE=Publ i s hed&wbc _pur pos e=Bas i c
9
- Quer y St r i ngModeUpdat e for working in Updat e mode
- Quer y St r i ngModeUnpubl i s hed for working in Unpubl i s hed mode We will use this technique in CMS Explorer to switch from
In order to get the Quer y St r i ngModeUnpubl i s hed property, we first need to get a reference to any
Cms Ht t pCont ex t
The drawback of using
Unpubl i s hed mode!
. We have successfully toggled to
Notice that the label now says Publishing mode: Unpublished
pr i v at e Cms Ht t pCont ex t c ms Cont ex t ; pr i v at e v oi d Page_Load( obj ec t s ender , Sy s t em. Ev ent Ar gs e) { c ms Cont ex t = Cms Ht t pCont ex t . Cur r ent ; / / Redi r ec t i f not i n unpubl i s hed mode i f ( c ms Cont ex t . Mode ! = Publ i s hi ngMode. Unpubl i s hed && c ms Cont ex t . Mode ! = Publ i s hi ngMode. Updat e) { s t r i ng quer y ; quer y = c ms Cont ex t . Root Channel . Quer y St r i ngModeUnpubl i s hed; Res pons e. Redi r ec t ( " def aul t . as px ?" + quer y ) ; } i f ( ! Page. I s Pos t Bac k ) { / / Di s pl ay t he publ i s hi ng mode l bl Publ i s hi ngMode. Tex t = " Publ i s hi ng Mode: "
event handler as follows:
Page_Load( )
mode, the page redirects to itself with the querystring returned by the Quer y St r i ngModeUnpubl i s hed property appended to its address. Modify the code in the
Unpubl i s hed
. In this example, we use the root channel. If we are not in
Channel I t em
Unpubl i shed mode.
mode to
Publ i shed
object:
Channel I t em
Toggling Modes with CmsHttpContext
When building your application, instead of messing around with the URLs, you can generate the
querystrings for each mode on the fly using two properties of theThis test shows how publishing modes in MCMS can be controlled by playing around with the querystring of the generated ugly URL.
Publ i s hed mode.
mode back to
Unpubl i s hed
Switch To Edit Site button! You have effectively changed from
Notice that the Switch To Live Site button changes back to the
- c ms Cont ex t . Mode. ToSt r i ng( ) ; } }
Save and build the solution. Navigate to ht t p: / / l oc al hos t / CMSEx pl or er / def aul t . as px again.
10 4. Click the Go button next to the address bar of the browser.
Building CMS Explorer
to toggle between modes is that it requires you to first get
a reference to a Channel I t em object as well as a client redirect. For this example, we used the root
channel. If the user does not have rights to the root channel, the code fails.- CmsHt t pCont ext . Cur r ent . Root Channel . Quer ySt r i ngModeUpdat e) ; }
object, first create a new instance of it:
Cms Appl i c at i onCont ex t
is that it reduces the number of client round trips required. We won't be using
Cms Appl i c at i onCont ex t
in the CMS Explorer application. Nevertheless, no lesson on mode switching is complete without introducing the class. The
CmsAppl i cat i onCont ext
class is covered extensively in Chapter 13, Essential How- Tos, Tips, and Tricks . To use the
Cms Appl i c at i onCont ex t
/ / Cr eat e a new Cms Appl i c at i onCont ex t Cms Appl i c at i onCont ex t c ms Cont ex t = new Cms Appl i c at i onCont ex t ( ) ;
Updat e
Unlike
Cms Ht t pCont ex t
,
Cms Appl i c at i onCont ex t
must be authenticated with the MCMS server
using one of four authentication methods. Each authentication method accepts an input parameter
of typePubl i s hi ngMode specifying the mode you wish to work in.
To authenticate as the current user:
mode. Another advantage to using
in
/ / aut hent i c at e as t he c ur r ent us er c ms Cont ex t . Aut hent i c at eAs Cur r ent Us er ( Publ i s hi ngMode. Unpubl i s hed) ;
You can also use the
Chapter 1
11 How can I toggle to Update mode?
To toggle to Updat e mode, simply use the Channel I t em. Quer ySt r i ngModeUpdat e property
instead, like so:i f ( CmsCont ext . Mode ! = Publ i shi ngMode. Updat e) { Response. Redi r ect ( " def aul t . aspx?"
Toggling Modes with CmsApplicationContext Another popular method of toggling between modes leverages the
CmsAppl i cat i onCont ext object.