Create and integrate custom webpart in Sharepoint 2007

By Perry

This shows complete procedure to create and integrate custom webpart in Sharepoint 2007.

A webpart is a reusable code component created in .NET to provide some functionality or to display some contents.

It contains one or more webpart zones where webparts can be placed. You can create webpart in ASP.NET rather than using Sharepoint itself. To add inbuilt webparts, click on site action -> Edit -> Add/edit webparts and select the one yu like to add into your sharepoint site.

To create custom webpart:
1. Create class library project in C# .NET
2. Add reference System.Web.dll
3. Create class inheriting from webpart class.

Snippet:

Using System.Web.UI.Webcontrols.Webparts;
namespace SPWebparts
{
Class myclass: Webpart
    {
Protected override OnPrerender(...) { Title --> "My title"; Allowminimize --> false; }
        Protected override void RenderContents(HtmlTextWriter writer){
writer.Write("Hello.. <br>");
}
}

The webpart class contains several properties such as Title, Width, etc. It contains virtual methods OnPrerender, CreateChildControls, RenderControl etc.

You can override OnPrerender method to initialize webpart properties. Use html text writer to produce html output.
 
To integrate the webpart with sharepoint site, in project debug menu, specify your sharepoint site link in start with site URL box. The refresh your site, goto site actions -> Edit panel -> Add webparts and you will see your webpart included. Very simple !

Related FAQs

This shows how to Create Mailbox and configuring Sharepoint outgoing email settings?
This thread shows how to Create Active Directory User accounts and Groups.
I tried to explain why form based authentication is not supported and how to configure it using third party tools.
The location of sharepoint hive 12.
Brief steps for applying specific theme to all sharepoint site pages programmatically.
Difference between Sharepoint Site and Application pages.
Create and integrate custom webpart in Sharepoint 2007  (815 Views)
Create New Account