Explanation:
We will create a Simple WebPart for SharePoint 2007 (MOSS or SharePoint Services 3.0). For Developing the WebPart we will use Visual Studio 2005 and Visual Studio Extensions for SharePoint 2007 Development.
We will create a Class library (.dll) and then Import that DLL to the SharePoint Manually.
1. Create Class library in Visual Studio 2005.
2. My SimpleWebPart Template (SimpleWebPart.cs) Code look like the Following:
using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
namespace SimpleWebPart
{
[Guid("ab2d3f05-ddd7-4f4b-a392-06fdd6f68c49")]
public class SimpleWebPart : System.Web.UI.WebControls.WebParts.WebPart
{
public SimpleWebPart()
{
this.ExportMode = WebPartExportMode.All;
}
protected override void Render(HtmlTextWriter writer)
{
// TODO: add custom rendering code here.
// writer.Write("Output HTML");
}
}
}
3. The Solution Explorer Creates On of each CS, Public key (.snk) and Assembly File. This will also automatically get reference of the Microsoft.Sharepoint Object.
4. The WebPart is Inherited from System.Web.UI.WebControls.WebParts.WebPart
5. In the Render method add just one line of code:
protected override void Render(HtmlTextWriter writer)
{
writer.Write("My simple WebPart for SharePoint 2007");
}
6. Now, Run the Project by pressing F5 key.
7. The Visual studio Extensions for SharePoint 2007 Development will take care of exporting your WebPart to your SharePoint Default Web Application.
8. After successful export Visual Studio will restart IIS and will pop-up with new Explorer window of your Default Web Application (Default Web Application uses Port- 80)
9. To add the WebPart to your Site you need to open the edit mode of the Site. Click “Site Settings” (Site bearbeiten in German). We are using German version but rule of Thumb in SharePoint is that Menu Items have same locations.
10. Click the WebPart Zone to add your WebPart to it. It will bring a Pop-up in which all activated WebParts will be listed. Find your WebPart in the List and Check it.
11. Click “Add” (Hizufügen in German) to add the SimpleWebPart.
12. You have your First WebPart in SharePoint now.
|