1 / 22

Module 3 Developing SharePoint 2010 Web Parts

Learn how to develop standard, connected, and visual web parts in SharePoint 2010 using Visual Studio 2010. Explore creating connection interfaces, provider and consumer web parts, and developing user interfaces and code for visual web parts.

Download Presentation

Module 3 Developing SharePoint 2010 Web Parts

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Module 3 Developing SharePoint 2010 Web Parts

  2. Module Overview • Developing Standard Web Parts • Developing Connected Web Parts • Developing Visual Web Parts • Lab: Creating SharePoint 2010 Web Parts by Using Visual Studio 2010

  3. Lesson 1: Developing Standard Web Parts • What Is a Standard Web Part? • Adding Standard Web Parts to Visual Studio 2010 Projects • Overriding Base Class Methods • Exposing Custom Properties in Web Parts

  4. What Is a Standard Web Part? • User's Perspective • Administrator's Perspective • Developer's Perspective • Class that inherits from System.Web.UI.WebControls.WebParts.WebPart

  5. Adding Standard Web Parts to Visual Studio 2010 Projects • Web Part is a SharePoint 2010 project item • Class is pre-configured with common using statements • Typical namespaces used in ASP.NET Web Parts • SharePoint namespaces • Adding additional namespaces • Class is pre-configured with an override for the most common method • CreateChildControls • Adding controls to the programmatic control tree • Overriding additional methods or properties

  6. Overriding Base Class Methods //Class-level object variables DateTimeControlfilterDate; ListViewByQueryMyCustomView; SPQuery query; protected override void CreateChildControls() { filterDate = new DateTimeControl(); filterDate.DateOnly = true; filterDate.AutoPostBack = true; filterDate.DateChanged += new EventHandler(filterDate_DateChanged); SPWebthisWeb = SPContext.Current.Web; MyCustomView = new ListViewByQuery(); MyCustomView.List = thisWeb.Lists["Interviews"]; query = new SPQuery(MyCustomView.List.DefaultView); query.ViewFields = "<FieldRef Name='Title' /><FieldRef Name='DueDate' />"; MyCustomView.Query = query; LiteralControlfilterMessage = new LiteralControl("Tasks due by:"); this.Controls.Add(filterMessage); this.Controls.Add(new LiteralControl("<br />")); this.Controls.Add(filterDate); this.Controls.Add(new LiteralControl("<br />")); this.Controls.Add(MyCustomView); } //Event handler for component in the control tree void filterDate_DateChanged(object sender, EventArgs e) { ... }

  7. Exposing Custom Properties in Web Parts //Private class-level variable for internal storage string myVariable = "My Default Value"; //Web Part property decoration [WebBrowsable(true), WebDisplayName("My Custom Property"), WebDescription("Provide a value for the custom property"), Personalizable(PersonalizationScope.Shared), Category("My Category")] public string MyProperty { get { return(myVariable); } set { myVariable = value; } } //Use the property protected override void CreateChildControls() { this.Controls.Add(new LiteralControl(this.myVariable)); }

  8. Lesson 2: Developing Connected Web Parts • What Are Connected Web Parts? • Creating Connection Interfaces • Creating Provider Web Parts • Creating Consumer Web Parts • Connecting Web Parts in SharePoint Sites

  9. What Are Connected Web Parts? • Two or more Web Parts that share data • Provider Web Parts • Consumer Web Parts • Provider and Consumer Web Parts • Scenarios • Master/details views of SharePoint Data • Other linked functionality

  10. Creating Connection Interfaces public interface IJobDef { //Declare interface members string JobDef { get; set; } }

  11. Creating Provider Web Parts public class JobDefinitions : WebPart, IJobDef { //Private class-level variable for internal storage string _JobDef; //Implement JobDef from interface public string JobDef { get { return (_JobDef); } set { _JobDef = value; } } //Create provider connection point [ConnectionProvider("Job")] public IJobDefSendJobName() { return (this); } }

  12. Creating Consumer Web Parts //Private class-level variable for internal storage string jobDefinition = string.Empty; //Create consumer connection point for a method //that consumes the interface [ConnectionConsumer("Job")] public void GetJob(IJobDef Job) { if(Job != null) { jobDefinition = Job.JobDef; } }

  13. Connecting Web Parts in SharePoint Sites • Edit provider or consumer Web Part. • Use the Web Part menu for provider Web Parts • Send <object> To Or • Use the Web Part menu for consumer Web Parts • Get <object> From

  14. Lesson 3: Developing Visual Web Parts • What Is a Visual Web Part? • Adding Visual Web Parts to Visual Studio 2010 Projects • Developing User Interfaces for Visual Web Parts • Developing Code for Visual Web Parts • Deploying Visual Web Parts from Visual Studio

  15. What Is a Visual Web Part? • User's Perspective • Web Part • Administrator's Perspective • ASP.NET user control in the SharePoint file system • Developer's Perspective • ASP.NET User Control with UI designers • Standard Web Part that loads the user control at run time

  16. Adding Visual Web Parts to Visual Studio 2010 Projects • Visual Web Part is a SharePoint 2010 project type, and a SharePoint project item type • ASP.NET user control is added to the project • Designer and markup (.ASCX) • Code-behind file (.CS or .VB) • Standard Web Part is added to the project • Includes Page.LoadControl() and Controls.Add() statements • Adding SharePoint namespaces to the user control

  17. Developing User Interfaces for Visual Web Parts • Design view • Source view • Split view • Adding user interface elements • Toolbox • Markup ... // Add UI Elements <asp:TreeView ID="overviewTree" runat="server" ShowLines="true" EnableViewState="true"> </asp:TreeView>

  18. Developing Code for Visual Web Parts // Add required namespaces using Microsoft.SharePoint; public partial class OverviewUserControl : UserControl { protected void Page_Load(object sender, EventArgs e) { //Create, add, and manipulate UI elements overviewTree.Nodes.Clear(); //Access SharePoint objects SPWebthisWeb = SPContext.Current.Web; ... } }

  19. Deploying Visual Web Parts from Visual Studio • As simple as deploying a standard Web Part • What really happens? • Visual Web Part restrictions • Sandboxed solutions

  20. Lab: Creating SharePoint 2010 Web Parts by Using Visual Studio 2010 • Exercise 1: Creating, Deploying, and Debugging a Simple Web Part by Using Visual Studio 2010 • Exercise 2: Using SharePoint Components in a Web Part • Exercise 3: Creating a Visual Web Part by Using Visual Studio 2010 Logon information Estimated time: 60minutes

  21. Lab Review • What type of project did you create to start with? • How did you create the first standard Web Part? • What components did you use in the standard Web Part? • How did you create the second Web Part? • How did you design the user interface for the Visual Web Part? • Where did you add code for the Visual Web Part?

  22. Module Review • In this module, you have learned to: • Develop Standard Web Parts • Develop Connected Web Parts • Develop Visual Web Parts

More Related