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

Specifying the Parent Container


In this example we plan to use a DataGrid to display a list of all the objects in the selected container. However, before we can get the DataGrid to display a list of objects, we need to specify a parent container. The parent container will be a channel, resource gallery, or template gallery. We’ll need this container to determine the objects to be displayed in the DataGrid. If the user hasn’t specified a parent container, we use the root containers (i.e. the Channels channel, the Templates template gallery, and the Resources resource gallery).

Above and within the Page_Load() event handler, add the following code:

// the current CmsHttpContext
private CmsHttpContext cmsContext;

// the parent container whose contents we are displaying
					private HierarchyItem startItem;
private void Page_Load(object sender, System.EventArgs e)
{
  cmsContext = CmsHttpContext.Current;

  // Get the URL of the current page
					string currentUrl = HttpContext.Current.Request.Url.ToString();

  // Redirect if not in unpublished mode
  if (cmsContext.Mode != PublishingMode.Unpublished
       && cmsContext.Mode != PublishingMode.Update)
  {
    string query;
    query = cmsContext.RootChannel.QueryStringModeUnpublished;
    Response.Redirect(currentUrl + "?" + query);
  }

  InitializeStartItem();

  if (!Page.IsPostBack)
  {
    // Display the publishing mode
    lblPublishingMode.Text = "Publishing Mode: "
                  + cmsContext.Mode.ToString();

   // use the start channel's display name as the
					// header for the page
					litCurrentContainer.Text = startItem.Name;
  }
}

Add the InitializeStartItem() method directly below the Page_Load() event handler:

private void InitializeStartItem()
{
  // determine the object type
  string cmsObject = "";
  if (Request.QueryString["CMSObject"] != null)
  {
    cmsObject = Request.QueryString["CMSObject"].ToString();
  }

  // determine the GUID of the working container
  string cmsObjectGuid = "";
  if (Request.QueryString["CMSObjectGuid"] != null)
  {
    cmsObjectGuid = Request.QueryString["CMSObjectGuid"].ToString();
  }

  if (cmsObjectGuid == "")
  {
    // if not specified, we start with channels
    startItem = cmsContext.Channel;
  }
  else
  {
    startItem = cmsContext.Searches.GetByGuid(cmsObjectGuid);
  }

  // no working container has been specified. Use the root containers
  if (startItem == null)
  {
    switch(cmsObject)
    {
      case "Templates":
        // using the root template gallery
        startItem = cmsContext.RootTemplateGallery;
        break;
      case "Resources":
        // using the root resource gallery
        startItem = cmsContext.RootResourceGallery;
        break;
      default:
        // using the root channel
        startItem = cmsContext.RootChannel;
        break;
    }
  }
}

The code first determines the type of objects you are working with: channels, template galleries, or resource galleries. It gets this information from the CMSObject querystring parameter.

For channels, the logic is straightforward. Information about the channel is available from the CmsHttpContext.Channel property. If it isn’t null, the DataGrid uses that as the start channel. Otherwise, the root container is assigned to startItem.

For template galleries and resource galleries, the current gallery item can’t be obtained from the current CmsHttpContext. For these objects, the PAPI gets the GUID of the working container from the CMSObjectGuid querystring parameter we inserted earlier.

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