ENTERPRISE

Microsoft Content Management Server : Building SharePoint Web Parts - Creating the Web Part, Defining Custom Properties for the Web Part

8/30/2012 3:17:49 AM

Creating the Web Part

We now have the Web Part project set up with the necessary references, so let’s create the Web Part.

1.
In Solution Explorer, right-click on the project name, and select Add New Item.

2.
Select the Web Part file template from the Code category, name it NavigationWebPart.cs, and click Open.

If you choose Consumer/Provider Web Part or Tool Part, several interfaces will be implemented to enable Web Part communication. For the navigation Web Part, we can use the generic Web Part template as it does not need to communicate with other Web Parts.


You should now see the NavigationWebPart.cs file in Solution Explorer and the code should be open in code view. As you will see from the generated code, a Web Part inherits from Microsoft.SharePoint.WebPartPages.WebPart, which in turn inherits from System.Web.UI.Control.

The NavigationWebPart class has attributes that are used by the Web Part infrastructure and Visual Studio .NET. Please remove the attribute DefaultProperty("Text") as the navigation Web Part will not have a default property. The class attributes should now be:

[ToolboxData("<{0}:NavigationWebPart runat=server></{0}:NavigationWebPart>"),
XmlRoot(Namespace="ExtensibleMCMSPageListingWebPart")]

					  

The ToolboxData attribute defines the display name of the Web Part for use in the Visual Studio .NET Toolbox. As the properties on the class will be serialized into the Web Part Storage System, we must define the XML namespace using the XmlRoot attribute.

Defining Custom Properties for the Web Part

We will now define and develop the custom properties that will be used to configure this Web Part. The table below lists all the custom properties that our Web Part will expose.

PropertyDescriptionData typeDefault ValueCategory
ModeThe Web Part mode that is used to specify data sources and exception handling, primarily used for troubleshootingenmMode {DebugWithTestData, DebugShowXml, DebugShowException, Production}ProductionMCMS Listing Mode
SortByThe sort order of the ChannelItemCollectionenmSortBy {Default, ChangeDate, DisplayName, DisplayPath, ExpiryDate, Importance, Ordinal, StartDate}DefaultMCMS Listing Configuration
StartchannelThe channel to list the child items ofString/Channels/MCMS Listing Configuration
PresentationXslThe XSL stylesheet used to control the presentation of the dataStringLoad from DefaultXsl.xsltMCMS Listing Presentation
TestxmlXML for testing the transformation without connecting to MCMSStringLoad from TestXml.xmlMCMS Listing Presentation

After the Web Part has been added to a Web Part page, its custom properties can be modified in the browser by selecting Modify Shared Web Part (or Modify Personal Web Part) from the top right corner of the Web Part.

As you can see above, the controls that are used for each property will vary based on the data type. The property we specified earlier, Mode, is of type enmMode, which has four possible values so the ToolPane renders a drop-down list. The ToolPane will also render a textbox for numbers and strings. Custom properties can be grouped using the Category attribute on the property and this allows us to group multiple properties, for example MCMS Listing Configuration.

Other  
  •  Microsoft Content Management Server : Building SharePoint Web Parts - The SharePoint MCMS Navigation Control, Creating the Web Part Project
  •  Active Directory Domain Services 2008 : Search Group Policy Objects
  •  Active Directory Domain Services 2008 : Export a Starter GPO, Import a Starter GPO
  •  The Very Successful Hardware That Microsoft Has Ever Produced
  •  Xen Virtualization - Managing Xen : Virtual Machine Manager
  •  Xen Virtualization - Managing Xen : XenMan—Installing and Running
  •  Dual-Core Or Quad-Core?
  •  IBM WebSphere Process Server 7 and Enterprise Service Bus 7 : Getting Started with WID (part 2) - Working with Modules and Libraries
  •  IBM WebSphere Process Server 7 and Enterprise Service Bus 7 : Getting Started with WID (part 1) - Business Integration perspective
  •  Google vs. Apple vs. Microsoft
  •  DSLs in Boo : Implementing the Scheduling DSL
  •  DSLs in Boo : Combining domain-driven design and DSLs
  •  Active Directory Domain Services 2008 : Restore Group Policy Objects and Starter GPOs
  •  Active Directory Domain Services 2008 : Comment Group Policy Objects and Starter GPOs, View, Print, and Save a Report for Group Policy Objects, Back Up Group Policy Objects and Starter GPOs
  •  Apple Society … Money x Property
  •  Active Directory Domain Services 2008 : Create a New Group Policy Object from a Starter GPO, Edit Group Policy Objects and Starter GPOs, Copy Group Policy Objects and Starter GPOs
  •  Active Directory Domain Services 2008 : Create Group Policy Objects, Delete Group Policy Objects, Create Starter GPOs, Delete Starter GPOs
  •  System Center Configuration Manager 2007 : Architecture Design Planning - Device Management Planning
  •  System Center Configuration Manager 2007 : Architecture Design Planning - Software Update Planning
  •  Programming .NET Components : Marshaling-by-Reference Activation Modes (part 2) - Server-Activated Singleton
  •  
    Most View
    Learn How To... Organize Your Photographs
    So What Is ‘Cloud’ And Why Should I Care? (Part 3)
    Apple MacBook Pro 13in
    Canon EOS 650D (Part 2)
    Cloud Services - Which cloud? (Part 1)
    Intel vs AMD - The Choice Is Harder Than Ever (Part 3)
    Sony NEX-F3 Review (Part 2)
    Swann OutbackCam Security Camera
    Improve Your Mac (Part 4) - Tips for saving bandwidth
    Windows 8 vs. OS X Mountain Lion (Part 3)
    Top 10
    G.Skill DDR3 SDRAM 32GB Review (Part 6)
    G.Skill DDR3 SDRAM 32GB Review (Part 5)
    G.Skill DDR3 SDRAM 32GB Review (Part 4)
    G.Skill DDR3 SDRAM 32GB Review (Part 3)
    G.Skill DDR3 SDRAM 32GB Review (Part 2)
    G.Skill DDR3 SDRAM 32GB Review (Part 1)
    Macbook Pro With 13in Retina Display Review (Part 3)
    Macbook Pro With 13in Retina Display Review (Part 2)
    Macbook Pro With 13in Retina Display Review (Part 1)
    Kensington Folio Trio For iPad