Book Image

Advanced Microsoft Content Management Server Development

Book Image

Advanced Microsoft Content Management Server Development

Overview of this book

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 the book. SPS 2003 enables enterprises to deploy an intelligent portal that seamlessly connects users, teams, and knowledge so that people can take advantage of relevant information across business processes to help them work more efficiently.You've mastered the basics of MCMS, and setup your own MCMS installation. 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. As a developer, the Publishing API (PAPI) is at the heart of your work with MCMS, and this book starts by taking you on the most detailed tour of the PAPI you will find anywhere. As a live example, a component that reveals the structure of your MCMS site is created, taking you through how to manage the common elements of MCMS programmatically. Getting SharePoint and MCMS to work together is the next stop in the book. You will see how to use SharePoint's search engine to search MCMS content, publish content between the two systems, and create SharePoint Web Parts to draw content from MCMS.To ease your everyday work with MCMS, there are chapters on placeholder validation, and some useful custom placeholders for common MCMS tasks, such as a date-time picker, a placeholder for multiple attachments, and a DataGrid placeholder among others. There are a number of ways to consume MCMS content from the outside world, and we look at two exciting ways here; RSS and InfoPath/Web Services. The InfoPath solution provides another interface to MCMS content that allows content authors to concentrate on content and not the presentation. The book is rounded off with a number of must-have MCMS tips and tricks. Revert a posting to a previous version Change a postingÔø???s template Build a recycle bin Deal with links to deleted resources Update a postingÔø???s properties directly from a template file Re-write ugly URLs to friendly URLs Export resource gallery items using the site deployment API (SDAPI) Configure the position and size of the Web Author Console Dialogs Get frames and IFrames to work correctly in a template file
Table of Contents (21 chapters)
Advanced Microsoft Content Management Server Development
Credits
About the Authors
About the Reviewers
Index

Updating Property Values


Look at the grid. Properties whose values we can modify using the PAPI have a CanWrite property value of true.

So far, we have only been reading property values and using Web Author to update them. Let’s attempt to change the Description property value using the PAPI.

In HTML view, add the code shown below (including the text markers) above the opening <asp:DataGrid> tag:

<p>
  <table>
  <tr>
    <td>Description:</td>
    <td>(Add the text box for the Description here)</td>
  </tr>
  <tr>
    <td colspan="2" align="right">
      (Add the Update button here)
      <INPUT type="button" value="Close" onclick="javascript:window.close();">
    </td>
  </tr>
  </table>
  (Add the Label for displaying error messages here)
</p>

Toggle to Design view. Drag and drop the following controls from the Web Forms section of the Toolbox and delete all text markers. We will be adding a textbox for entering the channel item’s new description, a button for saving it, and a label for showing error messages (if there are any). Arrange them as shown in the diagram below and set their properties accordingly.

Control

Property

Property Value

TextBox

ID

Rows

TextMode

txtDescription

3

MultiLine

Button

ID

Text

btnUpdate

Update

Label

ID

Text

lblErrorMessage

(empty string)

In the Page_Load() event handler, add code to read the Description of the current hierarchy item and display it on the screen.

private void Page_Load(object sender, System.EventArgs e)
{
  // Put user code to initialize the page here
  CmsHttpContext cmsContext = CmsHttpContext.Current;
  hItem = null;

  string cmsObjectGuid = "";
  if (Request.QueryString["CMSObjectGuid"] != null)
  {
    // template gallery items and resource gallery items
    cmsObjectGuid = Request.QueryString["CMSObjectGuid"];
    hItem = cmsContext.Searches.GetByGuid(cmsObjectGuid);
  }
  else
  {
    // channels and postings
    hItem = cmsContext.ChannelItem;
  }

  // list all properties and their values in the grid
  if (hItem != null)
  {
    litCurrentItem.Text = hItem.Path;
    if (!Page.IsPostBack)
					{
					txtDescription.Text = hItem.Description;
					}
    ListProperties();
  }
}

Toggle to Design mode and double-click on the btnUpdate button. In the btnUpdate_OnClick() event handler, we will write the code that updates the Description property value of the HierarchyItem based on the text entered into the textbox.

private void btnUpdate_Click(object sender, System.EventArgs e)
{
  try
					{
					// IMPORTANT: You must be in update mode for the code to work
					// update the description
					hItem.Description = txtDescription.Text;
					// commit the change
					CmsHttpContext.Current.CommitAll();
					// refresh the page to ensure that the change shows up in the
					// datagrid
					Response.Redirect(HttpContext.Current.Request.Url.ToString());
					}
					catch(Exception ex)
					{
					CmsHttpContext.Current.RollbackAll();
					// after a rollback the CMS context needs to be disposed.
					CmsHttpContext.Current.Dispose();
					lblErrorMessage.Text = ex.Message;
					}
}

Save and build the solution. Let’s test it to see if it works:

  1. 1. With the properties page open, click the Refresh button.

  2. 2. Enter TropicalGreen—Live the Sunny Side of Life in the Description field.

  3. 3. Click Update.

Look at the grid again. The description property of the TropicalGreen channel has been updated!