Abstract
Most websites and portals in particular, make a point of showing large amounts of content. This can be a feast for users, but in the long run it can also be a source of confusion. Many studies on Web usability have concluded that personalization is a key factor in successful Web sites. Giving users the tools to build a personalized view of the contents can mean the difference between an average and a superior Web site. You could say that cutting-edge Web sites are rich in content, have a consistent and modular design, and allow users to personalize the content. And one such method is using webparts in your websites. A webpart is an ASP.NET server tool which is added to webpart zone on web part pages by users at the run time.
This paper describes the capabilities of WebPart in a Website development. The intended audience is anyone looking for a conceptual overview of WebParts in SharePoint.
Overview
SharePoint WebParts are the building blocks of many pages as they represent a window of data opened in the user's display. WebParts are relatively simple and composable components that you use to build complex and personalizable pages. With the help of web parts you can customize the sharepoint site for both expanding the functionality as well as for bringing functionality from exterior applications. The idea, therefore, is building simple Web Parts that can connect to each other, share data, and complement each other's behavior. Put together, they can form an extensible, highly personalizable mechanism to have developers and power users build rich SharePoint contents.
Background
In the early days of development in SharePoint most of the developers were comfortable in developing the webparts using ASP.NET 2.0 webparts. But deploying them to a SharePoint site was a lengthier process. ASP.NET 2.0 webparts were developed using Web Control Library and user has to add some code in Assembly Information file. In addition, while deploying to the SharePoint site the webpart DLL had to be copied to the Bin Folder of the website in Inetpub. In Web.Config file of the website, you have to add the DLL reference as a safe control.
However, the development and deployment of the SharePoint WebPart became easier with Visual Studio extensions to WSS. The tool consists of various templates, such as Event Handler, List Definition and WebPart etc.
Technical Overview
SharePoint WebParts are integral part of a SharePoint website. There are many inbuilt SharePoint WebParts for a developer to use; also, many webparts are available on internet that could match the requirements. Another option is create a webpart to use for your SharePoint site.
The various inbuilt SharePoint webparts are categorized as:
-
List and Library WebParts: These webparts include webparts like Announcements, Calendar, any List in the site etc.
-
BDC WebParts: These are Business Data Catalog webparts, Sharepoint sites create its own database in SQL Server each time new site is created. BDC Webparts are used when a SharePoint site needs to fetch the data from custom designed database or some other database application like Oracle.
-
Filter WebParts: These webparts are used to filter the data based on user requirement such as BDC Filter, User Filter, Date Filter, Text Filter etc.
-
Outlook WebParts: These webparts display your content in MS Outlook using MS Exchange Server 2003 or later.
-
Search WebParts: These webparts are used to provide search facility on your site. Examples of Search WebParts are Advanced Search, People Search, and Search Summary etc.
-
Miscellaneous WebParts: These webparts include Content Editor WebParts, Page Viewer WebParts, and Form WebParts etc.
Almost all the inbuilt SharePoint WebParts are generic webparts, means that these webparts have properties that can be modified by the power user in SharePoint.
Example of a Generic WebPart
Consider the Content Editor WebPart, this webpart when in edit mode provides an option called "Rich Text Editor" where the user can type its content and display. Another option is "Source Editor" where you can edit the raw HTML that the Content Editor will render.
Similarly, in the Page Viewer WebPart user can set the link to display a webpage, folder or file in the webpart. Therefore, the advantage of Generic WebPart is that user can set the values as per the requirements.
How to develop a Generic WebPart ?
To develop a Generic WebPart in SharePoint you should be familiar with developing ASP.NET 2.0 WebParts using Visual Studio. The method of creating a Generic WebPart is more or less same as creating an ASP.NET Web part, the difference comes where you want to provide the user to set some values or fields in the webpart.
The developer has to set the fields as properties in the code in order to enable the user to edit the desired values. Apart from setting the fields as properties you also, have to add few attributes to the property so that user is able to see it while editing the webpart.
The sample code is as in the Snippet 1 below.
private string _name
[WebBrowsable(true),
Personalizable(PersonalizationScope.User),
WebDescription("Enter your name"),
Category("Custom Properties"),
WebDisplayName("Name")]
public string Name
{
get { return _name; }
set { _name = value; }
} |
Snippet 1
The attributes used in the snippet above are explained in Table 1 below.
Table 1: Attributes of Properties and their Description
Attribute |
Description |
WebBrowsable(true) |
This is used to allow Editing of the Web Part property. Without this the property will not be displayed in the Web Part task pane. |
WebDisplayName ("...") |
This attribute defines the text that is used to label the property in the Web Part task pane. |
Personalizable(PersonalizationScope.User) |
User scope means that personalized data will be user-specific. |
WebDescription ("...") |
This is an optional attribute and can contain anything you define. The description is displayed as a tooltip when hovering over the property in the Web Part task pane. |
Category ("...") |
This optional attribute is an organizing mechanism, defining where the property should reside in the Web Part task pane of SharePoint and also providing a grouping strategy for logically related properties. The default category is Miscellaneous. |
This concludes the brief conceptual overview of WebParts in Sharepoint.
Summary
Web Parts add a new level of versatility and power to SharePoint and related Web pages. Generic Web Parts are similar to ordinary Web Parts, except that they implement special custom properties that let them communicate with user at run time.