Friday, February 1, 2013

SharePoint 2010 - Custom Webparts

Many times you may come across a situation where OOB webparts would not satisfy all you business needs.  In such scenarios you can use Visual studio 2010 to create rich customized webparts using Server object model.

Types of Custom Webparts
Based upon your requirement you can choose either of the following type:-

1) Classic Webparts: Classic webparts can be created by deriving from the WebPart class. You must write the code from scratch, in the CreateChildControls method, to create the layout design of the Web Part, which can be time consuming. One of the challenges that you face when designing a Web Part that has a complex user interface (UI) is the lack of drag-and-drop support.

2) Visual Webparts: Visual webparts wraps user control inside a classic webpart, so that programmer could work on ascx file as for any other web project instead to have to resort to programmatically create the controls via the CreateChildControl method.

Note: Visual webparts evolved in SharePoint 2010 and can be used for easily creating webparts with rich UI. But the performance is somewhat less compared to classic webparts, since there is an overhead of loading the user controls

The  Solution Package (.wsp)
A solution package is a distribution package that delivers your custom SharePoint Server 2010 development work to the Web servers or the application servers in your server farm. Use solutions to package and deploy custom Features, site definitions, templates, layout pages, Web Parts, cascading style sheets, and assemblies.

Webpart Deployment
To deploy our sample Web Part, as well as any other Web Part implementation, we need to complete the following steps:
1) Build the class into a .NET assembly of type DLL.
2) Make the assembly available to the web application (putting it into GAC, or into web application local bin folder, or into Solution Gallery of current Site Collection).
3) Authorize the Web Part to execute within the SharePoint environment, by adding a specific configuration item into the web.config file of the current web application, declaring the Web Part as a “SafeControl.”
4) Load the Web Part into the Web Parts Gallery of the current site so that it is available to the end user.

Note: In previous versions all the above mentioned steps where done using STSADM.exe command only. But Visual Studio 2010 makes it easy to complete all these deployment steps. Simply select the Build | Deploy Solution to automatically deploy the Web Part on the website.

This is just an overview of custom webparts. In the coming posts we will create and explore the capabilities of custom webparts.

No comments:

Post a Comment