programming4us
programming4us
WEBSITE

Microsoft Content Management Server Development : Building SharePoint Web Parts - Building the Data Layer

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

The Web Part will generate XML that lists all the ChannelItems in the configured StartChannel using the configured SortOrder. The use of XML facilitates the separation of the presentation layer from the data layer. Our data layer will be another class in the Web Part project but it could have been placed in an entirely different assembly for further abstraction.

As we are using the MCMS Publishing API (PAPI), this Web Part will only run on an SPS/WSS server with MCMS installed as the PAPI cannot connect to remote MCMS servers. If SPS/WSS and MCMS live on different servers, one solution is to use Web Service calls from the Web Part to the MCMS server.


  1. In Visual Studio .NET, right-click on the ExtensibleMCMSPageListingWebPart project and choose Add New Item.

  2. Under the Add sub-menu, choose Add New Class.

  3. Enter NavigationWebPartMCMSIntegration as the name and click OK.

  4. Add a reference to Microsoft.ContentManagement.Publishing.dll. As with other library files from the Microsoft.ContentManagement namespace, this is found in the <install directory>/Microsoft Content Management Server/server/bin directory.

  5. You should now have the empty NavigationWebPartMCMSIntegration class on screen. Add the following namespaces to the new class file:

    using System;
    using Microsoft.ContentManagement.Publishing;
    							using System.Security.Principal;
    							using System.Web;
    							using System.Xml;
    							using System.IO;
  6. We will now add the GetListing() method, which connects to MCMS and generates the XML listing all the ChannelItems:

    public static System.Xml.XmlDocument GetListing(string StartChannelPath,
                               NavigationWebPart.enmSortBy sortBy)
    {
      // Get the channel from the searches object
      Channel startChannel = CmsHttpContext.Current.Searches.GetByPath(
                                               StartChannelPath) as Channel;
    
      // Was the channel found?
      if (startChannel != null)
      {
        // Get all Children from the Start Channel
        ChannelAndPostingCollection _Children = startChannel.AllChildren;
    
        // Sort the Items
        _Children = SortMCMSChannelItems(sortBy, _Children);
    
        // Declare the string writer and the XmlTextWriter
        StringWriter tw = new StringWriter();
        XmlTextWriter _Writer = new XmlTextWriter(tw);
    
        // Write the <Channel> element
        _Writer.WriteStartDocument();
        _Writer.WriteStartElement("Channel");
        _Writer.WriteAttributeString("path", startChannel.Path);
        _Writer.WriteAttributeString("displayname", startChannel.DisplayName);
    
        // Loop through all the channel items
        foreach (ChannelItem _ChannelItem in _Children)
        {
          // Write the ChannelItem element and set its attributes
          _Writer.WriteStartElement("ChannelItem");
          _Writer.WriteAttributeString("path", _ChannelItem.Path);
          _Writer.WriteAttributeString("url", _ChannelItem.Url);
          _Writer.WriteAttributeString("displayname",
                              _ChannelItem.DisplayName);
    
          // Check what type of Channel Item it is and set the type attribute
          if (_ChannelItem is Posting)
          {
            _Writer.WriteAttributeString("type", "Posting");
          }
          else
          {
            _Writer.WriteAttributeString("type", "Channel");
          }
          _Writer.WriteEndElement();
        }
        // Close the <Channel> element & finalize the XML document
    
        _Writer.WriteEndElement();
        _Writer.WriteEndDocument();
        _Writer.Flush();
        _Writer.Close();
        XmlDocument _ChannelItemsAsXml = new XmlDocument();
    
        // Load the text from the string writer into the XML document
        _ChannelItemsAsXml.LoadXml(tw.ToString());
    
        return(_ChannelItemsAsXml);
      }
      else
      {
        throw new Exception("The Channel (" + StartChannelPath
                          + ") could not be found or the user does not have "
                          + "subscriber rights on the channel.");
      }
    }
    
    					  

To sort the ChannelAndPostingCollection returned by MCMS, we add the SortMCMSChannelItems() method:

public static ChannelAndPostingCollection SortMCMSChannelItems(
                                 NavigationWebPart.enmSortBy SortBy,
                                 ChannelAndPostingCollection ChildItems)
{
  switch(SortBy)
  {
    case NavigationWebPart.enmSortBy.ChangeDate:
      ChildItems.SortByChangeDate();
      break;

    case NavigationWebPart.enmSortBy.DisplayName:
      ChildItems.SortByDisplayName();
      break;

    case NavigationWebPart.enmSortBy.DisplayPath:
      ChildItems.SortByDisplayPath();
      break;

    case NavigationWebPart.enmSortBy.ExpiryDate:
      ChildItems.SortByExpiryDate();
      break;

    case NavigationWebPart.enmSortBy.Importance:
      ChildItems.SortByImportance();
      break;

    case NavigationWebPart.enmSortBy.Ordinal:
      ChildItems.SortByOrdinal();
      break;

    case NavigationWebPart.enmSortBy.StartDate:
      ChildItems.SortByStartDate();
      break;

    default:
      break;
  }
  return(ChildItems);
}

					  

For ease of coding and efficiency, the GetListing() and SortMCMSChannelItems() methods are marked as static so they can be accessed without instantiating the NavigationWebPartMCMSIntegration class.


Now that our helper data layer class is in place, we must also create a test XML file in the solution that will be deployed to SharePoint as a resource.

  1. In Visual Studio .NET, right-click on the ExtensibleMCMSPageListingWebPart project and choose Add New Item.

  2. From the Categories pane, select Data and then select XML File.

  3. Enter TestXml.xml as the name and click Open.

XML and XSLT are case sensitive so be sure to use the correct case when adding elements within these files.


Enter the following XML into the file. This is similar XML to that which will be generated by the GetListing method.

<?xml version="1.0" standalone="no" ?>
<Channel path="/Channels/" displayname="Channels">
  <ChannelItem path="/Channels/Site/1" url="/Site/1.htm"
        displayname="Display 1" type="Posting" />
  <ChannelItem path="/Channels/Site/2" url="/Site/2.htm"
        displayname="Display 2" type="Posting" />
  <ChannelItem path="/Channels/Site/3" url="/Site/3.htm"
        displayname="Display 3" type="Posting" />
  <ChannelItem path="/Channels/Site/4" url="/Site/4.htm"
        displayname="Display 4" type="Posting" />
  <ChannelItem path="/Channels/Site/5" url="/Site/5.htm"
        displayname="Display 5" type="Posting" />
  <ChannelItem path="/Channels/Site/6" url="/Site/6.htm"
        displayname="Display 6" type="Posting" />
</Channel>

This code could be extended to mimic the ChannelItems from child channels as well, like so:

<?xml version="1.0" standalone="no" ?>
<Channel path="/Channels/" displayname="Channels">
  <ChannelItem path="/Channels/Site/5" url="/Site/5.htm"
        displayname="Display 5" type="Posting" />
  <ChannelItem path="/Channels/Site/6" url="/Site/6"
          displayname="Display 6" type="Channel">
  <ChannelItem path="/Channels/Site/6/1" url="/Site/6/1.htm"
          displayname="Display 6.1" type="Posting" />
  </ChannelItem>
</Channel>

But for now we will keep it simple and only list the items for the immediate channel.

Other  
 
Top 10
Free Mobile And Desktop Apps For Accessing Restricted Websites
MASERATI QUATTROPORTE; DIESEL : Lure of Italian limos
TOYOTA CAMRY 2; 2.5 : Camry now more comely
KIA SORENTO 2.2CRDi : Fuel-sipping slugger
How To Setup, Password Protect & Encrypt Wireless Internet Connection
Emulate And Run iPad Apps On Windows, Mac OS X & Linux With iPadian
Backup & Restore Game Progress From Any Game With SaveGameProgress
Generate A Facebook Timeline Cover Using A Free App
New App for Women ‘Remix’ Offers Fashion Advice & Style Tips
SG50 Ferrari F12berlinetta : Prancing Horse for Lion City's 50th
- Messages forwarded by Outlook rule go nowhere
- Create and Deploy Windows 7 Image
- How do I check to see if my exchange 2003 is an open relay? (not using a open relay tester tool online, but on the console)
- Creating and using an unencrypted cookie in ASP.NET
- Directories
- Poor Performance on Sharepoint 2010 Server
- SBS 2008 ~ The e-mail alias already exists...
- Public to Private IP - DNS Changes
- Send Email from Winform application
- How to create a .mdb file from ms sql server database.......
programming4us programming4us
programming4us
 
 
programming4us