developing and deploying custom web2007

14
Developing and Deploying Custom Web Parts for SharePoint Portal 2007 Overview and difference with SPS 2003: Develop ing Web Part for SharePoi nt Portal 2007 is different as compared to developing for SPS 2003. Web Parts Developed in .Net 1.1 for SPS 2003 used the SharePoint.WebPartPages namesp ace, however the Web Part in ASP.N et 2.0 is found under the System.Web.UI.WebControls.WebParts.  Development of Web Part in VS 2005 To Get Started with creating Custom Web Part for MOSS 2007 in Microsoft Visual Studio 2005, Open the IDE and create a new C# project, Select Class Library as Project Type. Name It as NewWebPart.

Upload: abhi

Post on 06-Apr-2018

220 views

Category:

Documents


0 download

TRANSCRIPT

8/2/2019 Developing and Deploying Custom Web2007

http://slidepdf.com/reader/full/developing-and-deploying-custom-web2007 1/14

eveloping and Deploying Custom Web Parts for SharePoint Portal 2007

eveloping Web Part for SharePoint Portal 2007 is different as compared to

eveloping for SPS 2003. Web Parts Developed in .Net 1.1 for SPS 2003 used thharePoint.WebPartPages namespace, however the Web Part in ASP.Net 2.0und under the System.Web.UI.WebControls.WebParts.

o Get Started with creating Custom Web Part for MOSS 2007 in Microsoft Visuatudio 2005, Open the IDE and create a new C# project, Select Class Library asroject Type. Name It as NewWebPart.

8/2/2019 Developing and Deploying Custom Web2007

http://slidepdf.com/reader/full/developing-and-deploying-custom-web2007 2/14

d a reference to the System.Web from .Net components into the project. The System.Web dll contains the required namespace

stem.Web.UI.WebControls.WebParts .

The Project explorer view rename the Class1.cs with NewWbPart.cs to be consistent with this example; this will result in renamin

ss name as well. With the help of “using” keyword include the namespaces as shown in the code example below. Derive / Extend

wWebPart Class from the WebPart Class ( System.Web.UI.WebControls.WebParts.WebPart), and add the code as shown below. T

eateChildren Control is same as in .Net 1.1, that it would create and add controls to this Web Part Class,. In this case I have only

ded a WebControl.Calender Object. The RenderControl Method is an override for the WebPart Base Class and calls the RenderChi

thod, this causes the Children Controls to be rendered on the Particular HtmlTextWriter passed as a parameter to the method.

ng System;

ng System.Collections.Generic;

ng System.Text;

ng System.Web;

ng System.Web.UI;

ng System.Web.UI.WebControls;

ng System.Web.UI.WebControls.WebParts;

8/2/2019 Developing and Deploying Custom Web2007

http://slidepdf.com/reader/full/developing-and-deploying-custom-web2007 3/14

mespace NewWepPart

public class NewWebPart : WebPart

{

protected override void CreateChildControls()

{

Calendar cldr = new Calendar();

cldr.Enabled = true;

cldr.ShowGridLines = true;

cldr.ShowTitle = true;

cldr.EnableViewState = true;

cldr.SelectedDate = DateTime.Now;

Controls.Add(cldr); ?

?

}

public override void RenderControl(HtmlTextWriter writer)

{

RenderChildren(writer);

}

}

ld the project and on successful built you are ready to Deploy the Web Part to the Portal Site.

order to deploy a web part to a SharePoint portal 2007 site, we must have the URL of the site to which we want our web part ne

deployed (displayed in fact). As it is mentioned earlier that the Web Parts developed in .Net 2.0 environment does have a .CAB

ject , instead an assembly is created on build of project. Now there are two choices to deploye the assembly to the SharePoint p

ectory.

Deploy the assembly to the Assembly Folder (GAC) (requires the assembly to be stron named).

Put the assembly to the bin folder of the portal directory.

the sake of simplicity, the later choice is being demonstrated in this example.

8/2/2019 Developing and Deploying Custom Web2007

http://slidepdf.com/reader/full/developing-and-deploying-custom-web2007 4/14

e MOSS 2007 creates every portal in the inetpub\wwwroot\wss folder. The easiest way to find the bin folder from these folder

rarchies is to go from inetmgr console. Locate the appropriate portal (for which u want to deploy the web part), identified with t

t number. Right click and have Properties. Under the Home Directory Tab, note the path in Local path text box. Verify if the

der exists in the specified path by opening it in browser. If the folder doesn’t exist then create one. Now copy the assembly form

ject output folder and paste it in bin folder of portal.

wever there is another work around for putting the assembly in to the portal’s bin folder again ad again each time the Web Part P

built with changes.

ght click on the project name (NewWebPart) in the VS.Net 2005 IDE and click properties. Under the Build page paste the sa

h copied from inetmgr console into the Output Path. As shown in figure below. This will result in the latest assembly automatic

ployed to the bin folder every time the project is built.

8/2/2019 Developing and Deploying Custom Web2007

http://slidepdf.com/reader/full/developing-and-deploying-custom-web2007 5/14

en though the assembly is present in the Portal’s Bin folder, there is another step required to make the Control (Web Part) assem

able on the Portal Pages. Since the control will need to render on multiple machines in different browsers with as many user acco

the organizations have. There is a need to declare the control as “safe”. To do so open the web.config file placed under the porta

ectory in the VS.Net 2005 IDE.

8/2/2019 Developing and Deploying Custom Web2007

http://slidepdf.com/reader/full/developing-and-deploying-custom-web2007 6/14

en edit the file in the section of SafeControls, create a new SafeControl entry for our assembly as shown below. Save the file and

SafeControls>

afeControl Assembly="NewWebPart" Namespace="NewWebPart" TypeName="*" Safe="True" />

< SPAN></< SPAN>SafeControls>

ce now the web part have been written and deployed to the desired portal’s directory. The next task is to use the web part on th

tal’s Site. The Web Part Deployed to the portal can be placed on any site within that Portal. For convenience this NewWebPart is

monstrated to be placed on the home page of default Portal.

en the portal site in the internet explorer; in this case http://oss1 is the URL for the default portal, ensuring that the current logg

er has the administrative rights on the portal site.

begin with, the first step is to add the newly deployed web to the Portal’s web part gallery, since the portal is using the configura

abases to keep record of the contents of the portal, our newly created web part’s information doesn’t exist in the database. We n

add the web part to the Web Part Gallery before we can use it.

8/2/2019 Developing and Deploying Custom Web2007

http://slidepdf.com/reader/full/developing-and-deploying-custom-web2007 7/14

do so, the following steps should be followed. Click on the Site Actions button and then select Site Setti

On the site settings page under Galleries column click on the Web Parts.

8/2/2019 Developing and Deploying Custom Web2007

http://slidepdf.com/reader/full/developing-and-deploying-custom-web2007 8/14

On the Web Part Gallery Page click on the New button, to add the new web part assembly t

e gallery.

8/2/2019 Developing and Deploying Custom Web2007

http://slidepdf.com/reader/full/developing-and-deploying-custom-web2007 9/14

8/2/2019 Developing and Deploying Custom Web2007

http://slidepdf.com/reader/full/developing-and-deploying-custom-web2007 10/14

On the New Web Parts page locate the NewWebPart in the list, check the check box on the

d click on the Populate Gallery button the top of the page. This will result in the Web Part

try creation in the Web Part Gallery list, and hence it can be used from now on from the

llery. It can be notices easily that the Web Parts developed form the new Frame work of 2.0

extension of .webpart after their names. Whereas in earlier versions, it was a .dwp file. B

e .webpart and .dwp files are the XML definition of the Web Part.

Until this step the web part is ready to be used on the site by selecting it from Web Pa

llery. Click on the Site Actions button on the page and then select Edit Page, this will mod

8/2/2019 Developing and Deploying Custom Web2007

http://slidepdf.com/reader/full/developing-and-deploying-custom-web2007 11/14

e appearance of the page to enable the edit view. In this view Web Part Zones are highlighte

at a user can add a web part to the zone, Click on the Add a Web Part button in the left zon

d the Web Part.

8/2/2019 Developing and Deploying Custom Web2007

http://slidepdf.com/reader/full/developing-and-deploying-custom-web2007 12/14

Select the NewWebPart from the web part list . it is found under the Misc section and th

ick on? Advanced Web Part gallery and options.

8/2/2019 Developing and Deploying Custom Web2007

http://slidepdf.com/reader/full/developing-and-deploying-custom-web2007 13/14

In the? Add Web Part Pane at right , select Home Gallery and then drag the NewWebPart fro

e pane into the Web Part Zone.

8/2/2019 Developing and Deploying Custom Web2007

http://slidepdf.com/reader/full/developing-and-deploying-custom-web2007 14/14

Click on the Exit Edit Mode link on the page and the site will return to the view mode.