programming4us
programming4us
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
  •  
    video
     
    Video tutorials
    - How To Install Windows 8

    - How To Install Windows Server 2012

    - How To Install Windows Server 2012 On VirtualBox

    - How To Disable Windows 8 Metro UI

    - How To Install Windows Store Apps From Windows 8 Classic Desktop

    - How To Disable Windows Update in Windows 8

    - How To Disable Windows 8 Metro UI

    - How To Add Widgets To Windows 8 Lock Screen

    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010
    programming4us programming4us
    programming4us
     
     
    programming4us