Sunday, September 2, 2007

Creating and deploying Sharepoint Web Parts

1. Create web part dll using visual studio.
This code will generate if select the project type as SharePoint=> Web part[ for this share point extension for Visual studio should installed.

Else create as a class library project with following steps:
a. add reference to C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions12ISAPIMicrosoft.SharePoint.dll
b. add reference to System.Web
c. Add following code:
Example code:
==========================================================
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 CalenderTimeZone
{
[Guid("dc632d8c-b62c-4ee2-9683-8ccab39de356")]
public class CalenderTimeZone : System.Web.UI.WebControls.WebParts.WebPart
{
public CalenderTimeZone()
{
this.ExportMode = WebPartExportMode.All;
}

protected override void Render(HtmlTextWriter writer)
{
// TODO: add custom rendering code here.
writer.Write("Test Data");
}
}
}

==========================================================

2. Add( as new xml file) manifest.xml with assembly name and dwp file name.
Eg: manifest.xml
==========================================================

<?xml version="1.0"?>

<WebPartManifest xmlns="http://schemas.microsoft.com/WebPart/v2/Manifest">

<Assemblies>

<Assembly FileName="CalenderTimeWebpart.dll">

<SafeControls>

<SafeControl

Assembly="CalenderTimeWebpart"

Namespace="CalenderTimeWebpart"

TypeName="*"

Safe="True" />

</SafeControls>

</Assembly>

</Assemblies>

<DwpFiles>

<DwpFile FileName="CalenderTimeWebpart.dwp"/>

</DwpFiles>

</WebPartManifest>


==========================================================


3. Add( as new xml file) dwp file( same name mentioned in manifest.xml, CalenderTimeZone.dwp) .
a. Set title and description of web part.
b. Geive full assembly name using any reflector
Eg: CalenderTimeZone.dwp)
==========================================================
<?xml version="1.0" encoding="utf-8"?>

<WebPart xmlns="http://schemas.microsoft.com/WebPart/v2" >

<Title>Calender Time</Title>

<Description>CalenderTimeZone.</Description>

<Assembly>CalenderTimeWebpart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3b056877482568e8</Assembly>

<TypeName>CalenderTimeWebpart.ShowTime</TypeName>

<!-- Specify initial values for any additional base class or custom properties here. -->

</WebPart>

==========================================================

4. Make assembly with strong name[ project properties -> Signing -> new -> give name , unselect password option].

Compile and build dll for webpart.

5. Add new CAB Project( file -> add new proj. -> other proj. typs -> CAB proj. )

6. Right click in CAB proj. in soution explorer and add Project Output.

5. Add file ( .dwp file and manifest.xml)

6. Save and build the cab file.

7. Deploy the wep part using stsadm

a. open cammand prompt
b. go to: C:/Program Files/Common Files/Microsoft Sharedweb server extensions/12/BIN
c. Run
stsadm -o addwppack -filename CabfilePathCab1.CAB -url http://ServerName -globalinstall -force
This will install wep part in server.

8. IISRESET

9. Open the sharepoint site.

10. Site Actions -> Site Settings -> Web Parts -> New -> Select the corresponding webpart and populate populate gallery

After this this web part will be available in wep part gallery list and can be use in nay page.


2 comments:

Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...

Maria try to use MOSS Solution Builder for your Deployment purpose.

Cheers,
-nn