SharePoint Web part programming

27
SharePoint Web parts Development Nguyen Ba Quang [email protected] http://basquang.spaces.live.com http://msdnvietnam.net/blogs/qua ng

description

 

Transcript of SharePoint Web part programming

Page 1: SharePoint Web part programming

SharePoint Web parts Development

Nguyen Ba Quang

[email protected]://basquang.spaces.live.comhttp://msdnvietnam.net/blogs/quang

Page 2: SharePoint Web part programming

© 2006 Microsoft Corporation.2 04/10/2023

Agenda

● Web Parts fundamentals● Develop simple Web Part using VS 2008● Customization and Personalization● Design Web Part using VS 2008 ● How to create AJAX and Silverlight Web Parts● Web Parts Verbs the new features● Web Parts Connections

Page 3: SharePoint Web part programming

© 2006 Microsoft Corporation.3 04/10/2023

Page 4: SharePoint Web part programming

© 2006 Microsoft Corporation.4 04/10/2023

Web Parts Fundamental

● Web Parts are the fundamental building blocks for SharePoint’s user interface

● Web Parts are used within the site to enable further collaboration or integration within the site context

● There are some built-in Web Part in WSS 3.0 and MOSS 2007– Content Editor Web Part– User Tasks Web Part– XML Web Part– Business Data Catalog Filter Web Part– Search Core Results Web Part– …

Page 5: SharePoint Web part programming

© 2006 Microsoft Corporation.5 04/10/2023

Web Part History

● Windows SharePoint Services 2.0 (WSS)– Designed with its own Web Part infrastructure– WSS serializes/stores/retrieves personalization data

● ASP.NET 2.0– Designed with newer universal Web Part infrastructure– Serializes/stores/retrieves personalization data– More flexible and more extensible than WSS– ASP.NET 2.0 does not support WSS v2 Web Parts

● Windows SharePoint Services 3.0 (WSS)– Backward-compatible with v2 Web Parts– Offers a layer on top of the ASP.NET 2.0 Web Part infrastructure

Page 6: SharePoint Web part programming

© 2006 Microsoft Corporation.6 04/10/2023

Web Part Types for WSS v3

WSS v2 Runtime

WSS Web PartsWSS Web Parts

WSS v3 RuntimeASP.NET 2.0 Runtime

ASP Web PartsASP Web Parts

Hybrid Web Parts

WSS Web Parts

WSS Web Parts

Page 7: SharePoint Web part programming

© 2006 Microsoft Corporation.7 04/10/2023

WSS v3 Web Part Page Structure

SPWebPartManager

SPWebPartZone (Left) SPWebPartZone (Right) Editor Zone

Catalog Zone

Web Part 1

Web Part 2

Web Part 3

Web Part 4

Web Part 5

Editor Part 1

Editor Part 2

Catalog Part 1

Catalog Part 2

Page 8: SharePoint Web part programming

© 2006 Microsoft Corporation.8 04/10/2023

Developing simple Web Part using VS 2008

● Web Parts derive from ASP.NET 2.0 WebPart base class

using System;using System.Web.UI;using System.Web.UI.WebControls.WebParts;

namespace HelloWebPart { [Guid("91f30b14-2172-4fbf-b0de-d9d28b5e3680")] public class HelloWorldWebPart : WebPart { protected override void CreateChildControls() {

base.CreateChildControls(); // TODO: add custom rendering code here. Label label = new Label(); label.Text = "Hello World"; this.Controls.Add(label);}

}}

Page 9: SharePoint Web part programming

© 2006 Microsoft Corporation.9 04/10/2023

Develop simple WebPart using VS 2008

● Step 1: Create new Project using SharePoint WebPart template

● Step 2: Override CreateChildControls in webpart classs● Step 3: Setting your SharePoint URL in Project properties

Debug tab Start Browser with URL● Step 4: Build and Deploy solution● Step 5: Ready to test in SharePoint pages

Page 10: SharePoint Web part programming

DEMO

Develop simple Web Part using VS 2008

Page 11: SharePoint Web part programming

© 2006 Microsoft Corporation.11 04/10/2023

Customization and Personalization

● Enable Web Parts to be reused for multiple business applications

● Customization refers to a change that is shared by all users of the Web Part instance.– Setting PersonalizationScope.Shared

● Personalization is specific to the individual user’s Web Part instance– Setting PersonalizationScope.User

● Editor Part is a special type of control that is used only to edit Web Part properties that support customization and personalization

Page 12: SharePoint Web part programming

© 2006 Microsoft Corporation.12 04/10/2023

Create custom Editor Pad

● Step 1: create new WebPart project● Step 2: Setting WebBrowsable to false in WebPart properties● Step 3: Override CreateEditorParts method● Step 4: Create new class derive from EditorPart● Step 5: define controls and override CreateChildControls● Step 6: override ApplyChanges and SyncChanges methods● Step 7: Setting your SharePoint URL in Project properties

Debug tab Start Browser with URL● Step 8: Build and Deploy solution● Step 9: Ready to test in SharePoint pages

Page 13: SharePoint Web part programming

DEMO

Create RSS Reader Web Part

Page 14: SharePoint Web part programming

© 2006 Microsoft Corporation.14 04/10/2023

Design Web Part using VS 2008

● Problems:– Design UI in Web Part– Reuse existing Web pages

● Solutions:– Using Web User Control– Design using VS 2008– Host in Web Part using Page.LoadControl

Page 15: SharePoint Web part programming

© 2006 Microsoft Corporation.15 04/10/2023

Create Web Part host User Controls

● Step 1: Create New WebPart project● Step 2: Override CreateChildControls

– Use Page.LoadControl to add UserControls

● Step 3: Create new Web Application project● Step 4: Create new Web User Controls● Step 5: Publish the Web Application to C:\inetpub\wwwroot\wss\

VirtualDirectories\[port number]\UserControls\● Step 6: Setting your SharePoint URL in Project properties

Debug tab Start Browser with URL● Step 7: Build and Deploy WebPart● Step 8: Ready to test in SharePoint pages

Page 16: SharePoint Web part programming

DEMO

Web Part host User Controls

Page 17: SharePoint Web part programming

© 2006 Microsoft Corporation.17 04/10/2023

AJAX and Silverlight Web Part

● Problems:– Using AJAX in SharePoint– Host Silverlight in SharePoint

● Solutions:– Create AJAX and Silverlight in VS 2008– Configure SharePoint web.config to enable AJAX and

Silverlight

Page 18: SharePoint Web part programming

© 2006 Microsoft Corporation.18 04/10/2023

Create AJAX and Silverlight Web Part

● Step 1: config your SharePoint site to work with .NET 3.5– Modify in web.config of SharePoint Application

● Step 2: Create new Web Part project in VS 2008● Step 3: Override OnLoad method to get ScriptManager object● Step 4: Create AJAX and Silverlight in other project● Step 5: Deploy your AJAX and Silverlight controls in SharePoint

folders● Step 6: Override CreateChildControls to Load AJAX and

Silverlight controls– Use Page.LoadControl to add AJAX user controls– Silverlight.Source to load Silverlight controls

Page 19: SharePoint Web part programming

DEMO

AJAX Web PartSilverlight Web Part

Page 20: SharePoint Web part programming

© 2006 Microsoft Corporation.20 04/10/2023

Web Part Verbs

● Web Part Verb is an action that is rendered in the Web Part menu by the Web Part framework

● Web Part Verb action support:– C lient-side function– Server-side handler

Page 21: SharePoint Web part programming

© 2006 Microsoft Corporation.21 04/10/2023

Create Web Part Verbs

● Step 1: Create new Web Part project using VS 2008● Step 2: Override Verbs Properties

public override WebPartVerbCollection Verbs { get { List<WebPartVerb> objVerbs = new List<WebPartVerb>();

WebPartVerb verb = new WebPartVerb(this.ID, new WebPartEventHandler(ServerSideHandler)); verb.Text = "Click to execute server side code"; verb.Visible = true; verb.Description = “Execute server side code"; objVerbs.Add(verb); WebPartVerbCollection allverbs = new WebPartVerbCollection(base.Verbs, objVerbs); return allverbs; } }

Page 22: SharePoint Web part programming

DEMO

Web Part Verbs

Page 23: SharePoint Web part programming

© 2006 Microsoft Corporation.23 04/10/2023

Web Part Connections

● Enables reuse among diverse applications● Frequently used for master/detail records● Simple implementation:

– Implementing custom interface– Using ConnectionProvider attribute– Using ConnectionConsumer attribute

Page 24: SharePoint Web part programming

© 2006 Microsoft Corporation.24 04/10/2023

Create Connectable Web Part

● Step 1: Create new WebPart project as WebPart provider● Step 2: Create new Interface● Step 3: Implement interface in WebPart provider● Step 4: Specify the data object with the ConnectionProvider

attribute● Step 5: Create new WebPart item in your project ● Step 6: Create a connection method with the

ConnectionConsumer attribute

Page 25: SharePoint Web part programming

DEMO

Web Part Connections

Page 26: SharePoint Web part programming

Resource and References

Microsoft SharePoint Products and Technologies Web sites

Web Parts in Windows SharePoint Services MSDN

Inside Microsoft Windows SharePoint Services 3.0 byTed PattisonandDaniel Larson

Microsoft Office SharePoint 2007 Technical Enablement Tour by Patrick Tisseghem (Managing Partner – U2U)

Page 27: SharePoint Web part programming

Section title hereSub title here