SharePoint Web part programming
Upcoming SlideShare
Loading in...5
×
 

SharePoint Web part programming

on

  • 1,992 views

 

Statistics

Views

Total Views
1,992
Views on SlideShare
1,992
Embed Views
0

Actions

Likes
0
Downloads
19
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • The primary task of the SharePoint developer is to build reusable components for business users. Business users in turn will take these components and build applications, customizing the application for the particular business need and personalizing the application for their own working style. This development mindset is in contrast to typical Windows or Web software that is deployed as a complete unit. With WSS technologies, the application is always evolving as business users employ deployed components to build their own applications and workspaces. Web Parts are used within the site to enable further collaboration or integration within the site context.Web Parts are the fundamental building blocks for SharePoint’s user interface, and with them we can build and integrate many different types of applications. The built-in Web Parts serve as good design examples when writing your own. For example, the Data View Web Part can be configured to point at any data source and display the data in many different ways. In the same way, all of the Web Parts that ship with WSS are generic and built for reuse. Although you may build more specific applications with Web Parts, it is important to be as generic as possible to allow the greatest flexibility for your customer, the business user, who can then configure the Web Part for a specific use.
  • Customization and personalization of Web Parts enable your 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, whereas personalization is specific to the individual user’s Web Part instance. For example, the site owner may choose a specific news feed to display on a site’s home page. This would be a customization, because the change would be shared by all users of the site. Individual users on the site may choose different rendering formats according to their preferences, which would be an example of personalization. Personalization applies to individual users and is persisted on a per-user basis.To add a new custom property, just add a public property and the Personalizable attribute. The WebBrowsable, WebDisplayName, WebDescription, and Category attributes also will be useful in administering the property from the Web Part’s Editor Parts. These attributes are defined in the System.Web.UI.WebControls.WebParts and System.ComponentModel namespaces.If you create a property and apply the WebBrowsable attribute, the Web Part framework will automatically display this property in a generic Editor Part when the user selects Modify Web Part. An Editor Part is a special type of control that is used only to edit Web Part properties that support customization and personalization
  • Sometimes you may have an existing Web page application that needs to be ported to SharePoint. It is relatively simple to do this by converting the pages to User Controls. Although User Controls aren’t recommended for all Web Part applications, they can be a quick way to get an ASP.NET application deployed into your SharePoint Web sites. User Controls deployed in SharePoint either must inherit from the UserControl class or from a UserControl-derived class that is available to the Web application (through either the bin directory or the GAC) and must exist in the same IIS Web application. Web Part code then can load the control and add it to your Web Part using the method Page.LoadControl. Since your User Control will exist on the file system and not in the content database, it can contain inline code if needed, since it isn’t processed through the Safe Mode Parser. Note that you cannot deploy User Controls through the content database. You only have to load the control and add it to the controls collection, and the Control framework will render it
  • Enabling .NET 3.5 in SharePoint 2007 Sites (Include AJAX and Silverlight)Start Visual Studio 2008.Create a new dummy ASP.NET Web Application Project, and make sure you target the .NET Framework 2.0 (upper right dropdown of the New Project dialog). The name of this project is not important; you won’t need it anymore when we’re done.Copy the web.configof your SharePoint 2007 site, into the dummy Web Application project in Visual Studio.Open the Project Properties in Visual Studio (right click on the Project node in the Solution Explorer, and choose Properties; or in the Project menu, select WebApplicationX Properties).Select .NET Framework 3.5 in the Target Framework dropdown (select Yes in the confirmation dialog).Copy the web.config from the Web Application Project back to SharePoint.
  • A Web Part Verb is an action that is rendered in the Web Part menu by the Web Part framework as part of the chrome that is rendered around the control. The action can call a client-side function or a server-side handler. To add Web Part Verbs as menu items, override the Verbs property of the Web Part. The Verbs property returns a read-only WebPartVerbCollection, so you will need to merge a collection of Verbs with the base.Verbs property to create a new WebPartVerbCollection.
  • Web Part connections are another Web Part technology that enables reuse among diverse applications. Connections are frequently used for master/detail records and are used in Web Parts for late-bound connections. As long as a Web Part provides data that your Web Part can consume, it can be connected using the Web Part frameworkConnections are enabled through the ConnectionProvider attribute. The simplest way to add a connection to your Web Part is by implementing a custom interface such as the ICustomerProvider interface and specifying the data object with the ConnectionProvider attribute. To connect to the provider Web Part, the consumer Web Part simply marks a connection method with the ConnectionConsumer attribute.

SharePoint Web part programming SharePoint Web part programming Presentation Transcript

  • Nguyen Ba Quangbasquang@hotmail.comhttp://basquang.spaces.live.comhttp://msdnvietnam.net/blogs/quangSharePointWeb parts Development
  • 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 Connections2 © 2006 Microsoft Corporation. 5/13/2012
  • 3 © 2006 Microsoft Corporation. 5/13/2012
  • 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 – …4 © 2006 Microsoft Corporation. 5/13/2012
  • 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 infrastructure5 © 2006 Microsoft Corporation. 5/13/2012
  • Web Part Types for WSS v3 ASP.NET 2.0 Runtime WSS v3 Runtime WSS Web Parts ASP Web Parts ASP Web Parts Hybrid Web Parts WSS v2 Runtime WSS Web Parts WSS Web Parts6 © 2006 Microsoft Corporation. 5/13/2012
  • WSS v3 Web Part Page Structure SPWebPartManager SPWebPartZone (Left) SPWebPartZone (Right) Editor Zone Web Part 1 Web Part 3 Editor Part 1 Web Part 2 Web Part 4 Editor Part 2 Web Part 5 Catalog Zone Catalog Part 1 Catalog Part 27 © 2006 Microsoft Corporation. 5/13/2012
  • Developing simple Web Part using VS 2008● Web Parts derive from ASP.NET 2.0 WebPart base classusing 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);} }}8 © 2006 Microsoft Corporation. 5/13/2012
  • 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 pages9 © 2006 Microsoft Corporation. 5/13/2012
  • DEMODevelop simple Web Part using VS 2008
  • 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 personalization11 © 2006 Microsoft Corporation. 5/13/2012
  • 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 pages12 © 2006 Microsoft Corporation. 5/13/2012
  • DEMOCreate RSS Reader Web Part
  • 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.LoadControl14 © 2006 Microsoft Corporation. 5/13/2012
  • 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:inetpubwwwrootwssVirtualDirectories[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 pages15 © 2006 Microsoft Corporation. 5/13/2012
  • DEMOWeb Part host User Controls
  • 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 Silverlight17 © 2006 Microsoft Corporation. 5/13/2012
  • 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 controls18 © 2006 Microsoft Corporation. 5/13/2012
  • DEMOAJAX Web PartSilverlight Web Part
  • 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: – Client-side function – Server-side handler20 © 2006 Microsoft Corporation. 5/13/2012
  • Create Web Part Verbs● Step 1: Create new Web Part project using VS 2008● Step 2: Override Verbs Propertiespublic override WebPartVerbCollection Verbs { get { List<WebPartVerb> objVerbs = new List<WebPartVerb>(); WebPartVerb verb = new WebPartVerb(this.ID, newWebPartEventHandler(ServerSideHandler)); verb.Text = "Click to execute server side code"; verb.Visible = true; verb.Description = “Execute server side code"; objVerbs.Add(verb); WebPartVerbCollection allverbs = newWebPartVerbCollection(base.Verbs, objVerbs); return allverbs; } }21 © 2006 Microsoft Corporation. 5/13/2012
  • DEMOWeb Part Verbs
  • Web Part Connections● Enables reuse among diverse applications● Frequently used for master/detail records● Simple implementation: – Implementing custom interface – Using ConnectionProvider attribute – Using ConnectionConsumer attribute23 © 2006 Microsoft Corporation. 5/13/2012
  • 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 attribute24 © 2006 Microsoft Corporation. 5/13/2012
  • DEMOWeb Part Connections
  • Resource and ReferencesMicrosoft SharePoint Products and Technologies Web sitesWeb Parts in Windows SharePoint Services MSDNInside Microsoft Windows SharePoint Services 3.0 byTed PattisonandDanielLarsonMicrosoft Office SharePoint 2007 Technical Enablement Tour by PatrickTisseghem (Managing Partner – U2U)
  • Section title hereSub title here