Pages

Tuesday 13 January 2009

MOSS 2007 'Hello world' WebPart

In order to develop moss 2007 webpart you will need

1. Visual Studio 2005/2008 or later.


2. You will also need network access to a Windows 2003/2008 server with SharePoint 2007 (WSS or MOSS) . One can also install Visual Studio 2005/8 on the development server.


3. Administration rights on your SharePoint server and also administration rights on SharePoint web application.




Step 1: Create a Class Library project in vs 2005


2. Add a reference to System.Web




3. create a simple Web Part that will print "Hello World!" . bellow class will inherits from the WebPart class in System.Web.UI.WebControls.WebParts. In order to render the Web Part we need to overrides the Render method. A HtmlTextWriter instance is passed into the Render method and can then be used to write markup to the page output.

Code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
namespace HelloWorld_Webpart
{
public class HelloWorld :WebPart
{
//test Hello world webpart
protected override void Render(HtmlTextWriter writer)
{
// base.Render(writer);
writer.Write("Hello World from Vijay");
}
}
}

4. Attach ur class library with a strong name key
5. Add the statements
using System.Security;
and
[assembly: AllowPartiallyTrustedCallers] to AssemblyInfo.cs file.

6. builds the project and copy the dll( HelloWorld Webpart.dll ) to C:\Inetpub\wwwroot\wss\VirtualDirectories\37459(Port no of web application)\bin
7. Add the webpart detail as safe control entry in webconfig file as
Reflector tool(free download)





No comments: