Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Advanced Microsoft Content Management Server Development

You're reading from   Advanced Microsoft Content Management Server Development Working with the Publishing API, Placeholders, Search, Web Services, RSS, and Sharepoint Integration

Arrow left icon
Product type Paperback
Published in Nov 2005
Publisher Packt
ISBN-13 9781904811534
Length 544 pages
Edition 1st Edition
Concepts
Arrow right icon
Toc

Table of Contents (21) Chapters Close

Advanced Microsoft Content Management Server Development
Credits
About the Authors
About the Reviewers
1. Building CMS Explorer FREE CHAPTER 2. Managing Channels and Postings with the PAPI 3. Managing Templates, Template Galleries, and Resources 4. Preparing Postings for Search Indexing 5. Searching MCMS with SharePoint 6. Publishing Content Between MCMS and SharePoint 7. Building SharePoint Web Parts 8. Useful Placeholder Controls 9. Validating Placeholder Controls 10. Staging Static Pages 11. InfoPath with MCMS Web Services 12. MCMS and RSS 13. Essential How-Tos, Tips, and Tricks 1. Setting up MCMS and SPS on the Same Virtual Server 2. MCMS Connector for SharePoint Technologies 3. Installing the Tropical Green Website 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!

You have been reading a chapter from
Advanced Microsoft Content Management Server Development
Published in: Nov 2005
Publisher: Packt
ISBN-13: 9781904811534
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image