SlideShare a Scribd company logo
Building SharePoint
Web Parts




Rob Windsor
rwindsor@portalsolutions.net
@robwindsor
What Are Web Parts?
• Small “chunks” of user interface and functionality
• Aggregated together to build page content
• Managed by end-users
   Add/remove web parts on a page
   Determine where web parts are placed on the page
   Set web part properties
• Concept and implementation not specific to
  SharePoint or ASP.NET
DEMO
iGoogle
Web Part History
• SharePoint 2003
   First version with web part infrastructure
   Web part types and infrastructure are specific to SharePoint
• ASP.NET 2.0
   Web part types and infrastructure added to ASP.NET
• SharePoint 2007
   Adds support for ASP.NET web parts
   Continues support for SharePoint web parts for backwards
    compatibility
• SharePoint 2010
   Same support as SharePoint 2007 in farm solutions
   Adds support for web parts in sandboxed solutions
Working with SharePoint Web Parts
• Web parts can be added to web part zones or wiki content
• Each web part has common “chrome”
    Title, border, verbs menu
• Closing a web part hides it; deleting a web part removes it
  from page
Web Part Properties
• Web parts properties used to tailor display and functionality
    Zip/Postal code in weather web part
    Stock code in stock ticker web part
• Properties support customization and personalization
    Customization effects shared view of part
    Personalization effects current users view of part
Web Part Gallery
• Site collection scoped
• Both .DWP and .WEBPART files as items
• SharePoint can discover new candidates from
  Web.config
• Maintain metadata
• Available out-of-the-box parts determined by
  edition and site template
Web Part Gallery
DEMO
Working with Web Parts
SharePoint Web Part Page Structure
• Inherits from WSS WebPartPage base class
• Contains one SPWebPartManager control
• Contains one or more WSS WebPartZone controls
          SPWebPartManager


        WebPartZone (Left)   WebPartZone (Right)    Editor Zone

                                                   Editor Part 1
           Web Part 1            Web Part 3

                                                   Editor Part 2
                                 Web Part 4
           Web Part 2

                                                   Catalog Zone
                                 Web Part 5
                                                   Catalog Part 1


                                                   Catalog Part 2
Building a Simple Web Part
• ASP.NET web parts are server controls
    WebPart type derives from Panel
    User interface described with code
• Override RenderContents
    Use HTML markup and JavaScript to build interface
• Override CreateChildControls
    Use Server Controls to build interface
• Two methods can be combined
  protected override void RenderContents(HtmlTextWriter writer)
  {
      writer.RenderBeginTag(HtmlTextWriterTag.H2);
      writer.Write("Hello, World");
      writer.RenderEndTag();
  }
Chrome and Web Part Gallery Properties
• Can set web part properties to change chrome
  values
• Can be done in three places
   Using code in the web part constructor
   Using CAML in the .webpart file
   Editing the web part properties in the browser
• Web part gallery group name set in element
  manifest
DEMO
Building a Simple Web Part
Composite Web Parts
• Contain server controls as children
• Declare controls as fields
• In CreateChildControls
     Create controls
     Set properties
     Add controls to web part Controls collection
     Use LiteralControl to add literal markup
• Populate controls in OnPreRender
Composite Web Parts
protected DropDownList ListsDropDown;
protected GridView ItemsGridView;

protected override void CreateChildControls() {
    ListsDropDown = new DropDownList();
    ListsDropDown.AutoPostBack = true;
    ListsDropDown.SelectedIndexChanged +=
        new EventHandler(ListsDropDown_SelectedIndexChanged);
    Controls.Add(ListsDropDown);
    Controls.Add(new LiteralControl("<br/><br/>"));

    ItemsGridView = new GridView();
    Controls.Add(ItemsGridView);
}
DEMO
Building a Composite Web
Part
Deploying Web Parts
• Add .webpart file to web part gallery
• Register assembly that implements the web part as
  safe control in web.config
• Copy assembly to:
   Global Assembly Cache
   bin folder of IIS Web Application
      Executes with reduced trust
Deploying Web Parts - 2
• Visual Studio tools automate deployment process
  during development
• Visual Studio deployment has conflict detection
   Will replace .webpart file in gallery
• Deployment via Powershell or stsadm does not
  have conflict detection
   Deployed .webpart files will not be replaced
DEMO
Web Part Deployment
Web Parts in Sandboxed Solutions
• Split page rendering
    Page code runs in ASP.NET worker process
    Sandboxed web part code runs in sandbox worker process
    HTML markup and JavaScript from two worker processes merged
• Sandbox restrictions
      Reduced set of server object model API
      Restricted access outside SharePoint
      No elevation of permissions
      Cannot deploy files to SharePoint system folders
      Must be ASP.NET web parts
      Can only use ASP.NET controls
      No web part connections
Visual Web Parts
•    Visual web parts combine a web part with a user control
•    User controls have full design experience in Visual Studio
•    User interface and code behind defined in user control
•    Web part “injects” user control dynamically using
     Page.LoadControl
    private const string _ascxPath = @"~/_CONTROLTEMPLATES/.../MyUserControl.ascx";

    protected override void CreateChildControls()
    {
        Control control = Page.LoadControl(_ascxPath);
        Controls.Add(control);
    }
Visual Web Parts and Sandboxed Solutions
• Native visual web part template not compatible
  with sandboxed solutions
   Attempts to deploy user control to system folders
• Visual Studio Power Tools contains a sandbox
  compatible template
   Markup in the user control is converted to code at design
    time
DEMO
Visual Web Parts
Web Part Properties
• Web Parts support persistent properties
• Configure properties via attributes
    Personalizable(param)
       Directs SharePoint to persist property value
       Parameter indicates if property may be personalized
    WebBrowsable(true)
       Directs SharePoint to generate interface to edit property
    WebDisplayName, WebDescription
       The prompt and tooltip that accompany the data entry element
    Category
       The group in which the properties will be shown

             [Personalizable(PersonalizationScope.Shared)]
             [WebBrowsable(true)]
             [WebDisplayName("Year")]
             [Category("Pluralsight")]
             public int Year { get; set; }
DEMO
Web Part Properties
Deactivating Web Part Features
• Deactivating a Feature that provisions .webpart
  files to the web part gallery effectively does nothing
    Files provisioned by a module are not automatically
     removed on deactivation
    That is, custom web parts remain in the gallery after the
     Feature has been deactivated
• You should add code to the feature receiver to
  remove the .webpart files from the gallery on
  deactivation
Deactivating Web Part Features
public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
    var site = properties.Feature.Parent as SPSite;
    if (site == null) return;

    var web = site.RootWeb;
    var list = web.Lists["Web Part Gallery"];

    var partNames = new string[] {
        "Simple.webpart", "Composite.webpart", "Visual.webpart",
        "Sandboxed.webpart", "Properties.webpart"
    };

    foreach (var partName in partNames)
    {
        var item = list.Items.OfType<SPListItem>().
            SingleOrDefault(i => i.Name == partName);
        if (item != null) item.Delete();
    }
}
DEMO
Web Part Properties
Creating Connectable Web Parts
• Pass data from one web part to another
• Loosely-coupled connection
     Communication managed by WebPartManager
     Provider web part supplies data
     Consumer web parts retrieve data
• Interface used to define data contract
     ASP.NET has standard connection contracts
     Can use custom connection contracts
• SharePoint provides user interface elements to establish connections
• Not compatible with sandboxed solutions
Web Part Connections
DEMO
Web Part Connections

More Related Content

What's hot (20)

PDF
Oracle ADF Task Flows for Beginners
DataNext Solutions
 
PPTX
SharePoint 2016 Platform Adoption Lessons Learned and Advanced Troubleshooting
John Calvert
 
PPTX
Introduction to ASP.Net MVC
Sagar Kamate
 
PPTX
Asp.Net Mvc
micham
 
PDF
ASP.NET Overview - Alvin Lau
Spiffy
 
PPTX
SFDC UI - Introduction to Visualforce
Sujit Kumar
 
PPTX
New Features of ASP.NET 4.0
Buu Nguyen
 
PPSX
ASP.NET Web form
Md. Mahedee Hasan
 
PPS
11 asp.net session16
Niit Care
 
PDF
Integrating ASP.NET AJAX with SharePoint
Rob Windsor
 
PPTX
SharePoint Development (Lesson 3)
MJ Ferdous
 
PPTX
SharePoint 2010 Client-side Object Model
Phil Wicklund
 
PPTX
Oracle ADF Case Study
Jean-Marc Desvaux
 
PPT
ASP.NET 4.0 Roadmap
Harish Ranganathan
 
PPTX
SFDC UI - Advanced Visualforce
Sujit Kumar
 
PDF
How we rest
ColdFusionConference
 
PPTX
Sps redmond 2014 deck
Dorinda Reyes
 
PPSX
All About Asp Net 4 0 Hosam Kamel
Hosam Kamel
 
PPS
03 asp.net session04
Niit Care
 
PDF
Grails patterns and practices
paulbowler
 
Oracle ADF Task Flows for Beginners
DataNext Solutions
 
SharePoint 2016 Platform Adoption Lessons Learned and Advanced Troubleshooting
John Calvert
 
Introduction to ASP.Net MVC
Sagar Kamate
 
Asp.Net Mvc
micham
 
ASP.NET Overview - Alvin Lau
Spiffy
 
SFDC UI - Introduction to Visualforce
Sujit Kumar
 
New Features of ASP.NET 4.0
Buu Nguyen
 
ASP.NET Web form
Md. Mahedee Hasan
 
11 asp.net session16
Niit Care
 
Integrating ASP.NET AJAX with SharePoint
Rob Windsor
 
SharePoint Development (Lesson 3)
MJ Ferdous
 
SharePoint 2010 Client-side Object Model
Phil Wicklund
 
Oracle ADF Case Study
Jean-Marc Desvaux
 
ASP.NET 4.0 Roadmap
Harish Ranganathan
 
SFDC UI - Advanced Visualforce
Sujit Kumar
 
Sps redmond 2014 deck
Dorinda Reyes
 
All About Asp Net 4 0 Hosam Kamel
Hosam Kamel
 
03 asp.net session04
Niit Care
 
Grails patterns and practices
paulbowler
 

Viewers also liked (16)

PDF
Trono di spade1
jugiu
 
PPTX
SharePoint Logging and Debugging: The Troubleshooter’s Best Friend by Jason H...
SPTechCon
 
PPT
Counseling
bharatkeyur
 
PPTX
Part II: SharePoint 2013 Administration by Todd Klindt and Shane Young - SPTe...
SPTechCon
 
PPTX
SharePoint Performance: Best Practices from the Field by Jason Himmelstein - ...
SPTechCon
 
PPTX
Winchester Bluff Presentation 3_1_13
bickley2345
 
PPTX
Part I: SharePoint 2013 Administration by Todd Klindt and Shane Young - SPTec...
SPTechCon
 
PPTX
How to best setup SharePoint 2013, Web Apps, Workflow Manager with Powershell
Samuel Zürcher
 
PPTX
Sponsored Session: Driving the business case and user adoption for SharePoint...
SPTechCon
 
PPTX
Demystifying share point site definitions SharePoint 2007
Marwan Tarek
 
PPTX
Microsoft Keynote by Richard Riley - SPTechCon
SPTechCon
 
PPTX
SharePoint Search Center Configuration by Matthew McDermott - SPTechCon
SPTechCon
 
PPTX
Solving Enterprise Search Challenges with SharePoint 2010 by Matthew McDermot...
SPTechCon
 
PPTX
Tutorial: Building Apps for SharePoint 2013 Inside and Outside of the Firewal...
SPTechCon
 
PPTX
Farewell XSL, Welcome Display Templates
Elio Struyf
 
PDF
NOW I Get It... What SharePoint Is, and Why My Business Needs It by Mark Rack...
SPTechCon
 
Trono di spade1
jugiu
 
SharePoint Logging and Debugging: The Troubleshooter’s Best Friend by Jason H...
SPTechCon
 
Counseling
bharatkeyur
 
Part II: SharePoint 2013 Administration by Todd Klindt and Shane Young - SPTe...
SPTechCon
 
SharePoint Performance: Best Practices from the Field by Jason Himmelstein - ...
SPTechCon
 
Winchester Bluff Presentation 3_1_13
bickley2345
 
Part I: SharePoint 2013 Administration by Todd Klindt and Shane Young - SPTec...
SPTechCon
 
How to best setup SharePoint 2013, Web Apps, Workflow Manager with Powershell
Samuel Zürcher
 
Sponsored Session: Driving the business case and user adoption for SharePoint...
SPTechCon
 
Demystifying share point site definitions SharePoint 2007
Marwan Tarek
 
Microsoft Keynote by Richard Riley - SPTechCon
SPTechCon
 
SharePoint Search Center Configuration by Matthew McDermott - SPTechCon
SPTechCon
 
Solving Enterprise Search Challenges with SharePoint 2010 by Matthew McDermot...
SPTechCon
 
Tutorial: Building Apps for SharePoint 2013 Inside and Outside of the Firewal...
SPTechCon
 
Farewell XSL, Welcome Display Templates
Elio Struyf
 
NOW I Get It... What SharePoint Is, and Why My Business Needs It by Mark Rack...
SPTechCon
 
Ad

Similar to Tutorial, Part 4: SharePoint 101: Jump-Starting the Developer by Rob Windsor - SPTec… (20)

PPTX
Parallelminds.web partdemo1
parallelminder
 
PPTX
Parallelminds.web partdemo
ManishaChothe
 
PPTX
SharePoint 2010 Training Session 5
Usman Zafar Malik
 
PPTX
SharePoint Web part programming
Quang Nguyễn Bá
 
PPSX
15 asp.net session22
Vivek Singh Chandel
 
PPS
15 asp.net session22
Niit Care
 
PPT
Creating Web Parts New
LiquidHub
 
PPT
Creating Web Parts New
LiquidHub
 
PPT
Creating Web Parts New
LiquidHub
 
PPS
SharePoint 2007 Presentation
Ajay Jain
 
PPTX
Share Point Web Parts 101
Joseph Ackerman
 
PPTX
Deep dive into share point framework webparts
Prabhu Nehru
 
PPTX
Popping the Hood: How to Create Custom SharePoint Branding by Randy Drisgill ...
SPTechCon
 
PPTX
SharePoint Design & Development
Jonathan Schultz
 
DOCX
Diff sand box and farm
Rajkiran Swain
 
PPTX
Hdv309 - Real World Sandboxed Solutions
woutervugt
 
PPTX
Help! I've got a share point site! Now What?
Becky Bertram
 
PPT
SharePoint Developer Education Day Palo Alto
llangit
 
PPTX
Developing Branding Solutions for 2013
Thomas Daly
 
PPTX
SharePoint 2010 Pages
Elliot Chen
 
Parallelminds.web partdemo1
parallelminder
 
Parallelminds.web partdemo
ManishaChothe
 
SharePoint 2010 Training Session 5
Usman Zafar Malik
 
SharePoint Web part programming
Quang Nguyễn Bá
 
15 asp.net session22
Vivek Singh Chandel
 
15 asp.net session22
Niit Care
 
Creating Web Parts New
LiquidHub
 
Creating Web Parts New
LiquidHub
 
Creating Web Parts New
LiquidHub
 
SharePoint 2007 Presentation
Ajay Jain
 
Share Point Web Parts 101
Joseph Ackerman
 
Deep dive into share point framework webparts
Prabhu Nehru
 
Popping the Hood: How to Create Custom SharePoint Branding by Randy Drisgill ...
SPTechCon
 
SharePoint Design & Development
Jonathan Schultz
 
Diff sand box and farm
Rajkiran Swain
 
Hdv309 - Real World Sandboxed Solutions
woutervugt
 
Help! I've got a share point site! Now What?
Becky Bertram
 
SharePoint Developer Education Day Palo Alto
llangit
 
Developing Branding Solutions for 2013
Thomas Daly
 
SharePoint 2010 Pages
Elliot Chen
 
Ad

More from SPTechCon (20)

PPTX
Deep Dive into the Content Query Web Part by Christina Wheeler - SPTechCon
SPTechCon
 
PPTX
“Managing Up” in Difficult Situations by Bill English - SPTechCon
SPTechCon
 
PPTX
Ten Best SharePoint Features You’ve Never Used by Christian Buckley - SPTechCon
SPTechCon
 
PPTX
Looking Under the Hood: How Your Metadata Strategy Impacts Everything You Do ...
SPTechCon
 
PPTX
Law & Order: Content Governance Strategies by Chrisitan Buckley - SPTechCon
SPTechCon
 
PPTX
What IS SharePoint Development? by Mark Rackley - SPTechCon
SPTechCon
 
PPTX
The SharePoint and jQuery Guide by Mark Rackley - SPTechCon
SPTechCon
 
PPTX
Understanding and Implementing Governance for SharePoint 2010 by Bill English...
SPTechCon
 
PPTX
Integrate External Data with the Business Connectivity Services by Tom Resing...
SPTechCon
 
PDF
Converting an E-mail Culture into a SharePoint Culture by Robert Bogue - SPTe...
SPTechCon
 
PPTX
Tutorial: Best Practices for Building a Records-Management Deployment in Shar...
SPTechCon
 
PDF
Tutorial: Building Business Solutions: InfoPath & Workflows by Jennifer Mason...
SPTechCon
 
PDF
Creating Simple Dashboards Using Out-of-the-Box Web Parts by Jennifer Mason- ...
SPTechCon
 
PDF
Sponsored Session: Better Document Management Using SharePoint by Roland Simo...
SPTechCon
 
PDF
Sponsored Session: The Missing Link: Content-Aware Integration to SharePoint ...
SPTechCon
 
PPTX
Creating a Great User Experience in SharePoint by Marc Anderson - SPTechCon
SPTechCon
 
PPTX
Tutorial: SharePoint 2013 Admin in the Hybrid World by Jason Himmelstein - SP...
SPTechCon
 
PPTX
Business Intelligence in SharePoint 2013 by Jason Himmelstein - SPTechCon
SPTechCon
 
PDF
Piloting with SharePoint—Learn to FLY by Eric Riz - SPTechCon
SPTechCon
 
PDF
Write the Right Requirements by Eric Riz - SPTechCon
SPTechCon
 
Deep Dive into the Content Query Web Part by Christina Wheeler - SPTechCon
SPTechCon
 
“Managing Up” in Difficult Situations by Bill English - SPTechCon
SPTechCon
 
Ten Best SharePoint Features You’ve Never Used by Christian Buckley - SPTechCon
SPTechCon
 
Looking Under the Hood: How Your Metadata Strategy Impacts Everything You Do ...
SPTechCon
 
Law & Order: Content Governance Strategies by Chrisitan Buckley - SPTechCon
SPTechCon
 
What IS SharePoint Development? by Mark Rackley - SPTechCon
SPTechCon
 
The SharePoint and jQuery Guide by Mark Rackley - SPTechCon
SPTechCon
 
Understanding and Implementing Governance for SharePoint 2010 by Bill English...
SPTechCon
 
Integrate External Data with the Business Connectivity Services by Tom Resing...
SPTechCon
 
Converting an E-mail Culture into a SharePoint Culture by Robert Bogue - SPTe...
SPTechCon
 
Tutorial: Best Practices for Building a Records-Management Deployment in Shar...
SPTechCon
 
Tutorial: Building Business Solutions: InfoPath & Workflows by Jennifer Mason...
SPTechCon
 
Creating Simple Dashboards Using Out-of-the-Box Web Parts by Jennifer Mason- ...
SPTechCon
 
Sponsored Session: Better Document Management Using SharePoint by Roland Simo...
SPTechCon
 
Sponsored Session: The Missing Link: Content-Aware Integration to SharePoint ...
SPTechCon
 
Creating a Great User Experience in SharePoint by Marc Anderson - SPTechCon
SPTechCon
 
Tutorial: SharePoint 2013 Admin in the Hybrid World by Jason Himmelstein - SP...
SPTechCon
 
Business Intelligence in SharePoint 2013 by Jason Himmelstein - SPTechCon
SPTechCon
 
Piloting with SharePoint—Learn to FLY by Eric Riz - SPTechCon
SPTechCon
 
Write the Right Requirements by Eric Riz - SPTechCon
SPTechCon
 

Tutorial, Part 4: SharePoint 101: Jump-Starting the Developer by Rob Windsor - SPTec…

  • 2. What Are Web Parts? • Small “chunks” of user interface and functionality • Aggregated together to build page content • Managed by end-users  Add/remove web parts on a page  Determine where web parts are placed on the page  Set web part properties • Concept and implementation not specific to SharePoint or ASP.NET
  • 4. Web Part History • SharePoint 2003  First version with web part infrastructure  Web part types and infrastructure are specific to SharePoint • ASP.NET 2.0  Web part types and infrastructure added to ASP.NET • SharePoint 2007  Adds support for ASP.NET web parts  Continues support for SharePoint web parts for backwards compatibility • SharePoint 2010  Same support as SharePoint 2007 in farm solutions  Adds support for web parts in sandboxed solutions
  • 5. Working with SharePoint Web Parts • Web parts can be added to web part zones or wiki content • Each web part has common “chrome”  Title, border, verbs menu • Closing a web part hides it; deleting a web part removes it from page
  • 6. Web Part Properties • Web parts properties used to tailor display and functionality  Zip/Postal code in weather web part  Stock code in stock ticker web part • Properties support customization and personalization  Customization effects shared view of part  Personalization effects current users view of part
  • 7. Web Part Gallery • Site collection scoped • Both .DWP and .WEBPART files as items • SharePoint can discover new candidates from Web.config • Maintain metadata • Available out-of-the-box parts determined by edition and site template
  • 10. SharePoint Web Part Page Structure • Inherits from WSS WebPartPage base class • Contains one SPWebPartManager control • Contains one or more WSS WebPartZone controls SPWebPartManager WebPartZone (Left) WebPartZone (Right) Editor Zone Editor Part 1 Web Part 1 Web Part 3 Editor Part 2 Web Part 4 Web Part 2 Catalog Zone Web Part 5 Catalog Part 1 Catalog Part 2
  • 11. Building a Simple Web Part • ASP.NET web parts are server controls  WebPart type derives from Panel  User interface described with code • Override RenderContents  Use HTML markup and JavaScript to build interface • Override CreateChildControls  Use Server Controls to build interface • Two methods can be combined protected override void RenderContents(HtmlTextWriter writer) { writer.RenderBeginTag(HtmlTextWriterTag.H2); writer.Write("Hello, World"); writer.RenderEndTag(); }
  • 12. Chrome and Web Part Gallery Properties • Can set web part properties to change chrome values • Can be done in three places  Using code in the web part constructor  Using CAML in the .webpart file  Editing the web part properties in the browser • Web part gallery group name set in element manifest
  • 14. Composite Web Parts • Contain server controls as children • Declare controls as fields • In CreateChildControls  Create controls  Set properties  Add controls to web part Controls collection  Use LiteralControl to add literal markup • Populate controls in OnPreRender
  • 15. Composite Web Parts protected DropDownList ListsDropDown; protected GridView ItemsGridView; protected override void CreateChildControls() { ListsDropDown = new DropDownList(); ListsDropDown.AutoPostBack = true; ListsDropDown.SelectedIndexChanged += new EventHandler(ListsDropDown_SelectedIndexChanged); Controls.Add(ListsDropDown); Controls.Add(new LiteralControl("<br/><br/>")); ItemsGridView = new GridView(); Controls.Add(ItemsGridView); }
  • 17. Deploying Web Parts • Add .webpart file to web part gallery • Register assembly that implements the web part as safe control in web.config • Copy assembly to:  Global Assembly Cache  bin folder of IIS Web Application  Executes with reduced trust
  • 18. Deploying Web Parts - 2 • Visual Studio tools automate deployment process during development • Visual Studio deployment has conflict detection  Will replace .webpart file in gallery • Deployment via Powershell or stsadm does not have conflict detection  Deployed .webpart files will not be replaced
  • 20. Web Parts in Sandboxed Solutions • Split page rendering  Page code runs in ASP.NET worker process  Sandboxed web part code runs in sandbox worker process  HTML markup and JavaScript from two worker processes merged • Sandbox restrictions  Reduced set of server object model API  Restricted access outside SharePoint  No elevation of permissions  Cannot deploy files to SharePoint system folders  Must be ASP.NET web parts  Can only use ASP.NET controls  No web part connections
  • 21. Visual Web Parts • Visual web parts combine a web part with a user control • User controls have full design experience in Visual Studio • User interface and code behind defined in user control • Web part “injects” user control dynamically using Page.LoadControl private const string _ascxPath = @"~/_CONTROLTEMPLATES/.../MyUserControl.ascx"; protected override void CreateChildControls() { Control control = Page.LoadControl(_ascxPath); Controls.Add(control); }
  • 22. Visual Web Parts and Sandboxed Solutions • Native visual web part template not compatible with sandboxed solutions  Attempts to deploy user control to system folders • Visual Studio Power Tools contains a sandbox compatible template  Markup in the user control is converted to code at design time
  • 24. Web Part Properties • Web Parts support persistent properties • Configure properties via attributes  Personalizable(param)  Directs SharePoint to persist property value  Parameter indicates if property may be personalized  WebBrowsable(true)  Directs SharePoint to generate interface to edit property  WebDisplayName, WebDescription  The prompt and tooltip that accompany the data entry element  Category  The group in which the properties will be shown [Personalizable(PersonalizationScope.Shared)] [WebBrowsable(true)] [WebDisplayName("Year")] [Category("Pluralsight")] public int Year { get; set; }
  • 26. Deactivating Web Part Features • Deactivating a Feature that provisions .webpart files to the web part gallery effectively does nothing  Files provisioned by a module are not automatically removed on deactivation  That is, custom web parts remain in the gallery after the Feature has been deactivated • You should add code to the feature receiver to remove the .webpart files from the gallery on deactivation
  • 27. Deactivating Web Part Features public override void FeatureDeactivating(SPFeatureReceiverProperties properties) { var site = properties.Feature.Parent as SPSite; if (site == null) return; var web = site.RootWeb; var list = web.Lists["Web Part Gallery"]; var partNames = new string[] { "Simple.webpart", "Composite.webpart", "Visual.webpart", "Sandboxed.webpart", "Properties.webpart" }; foreach (var partName in partNames) { var item = list.Items.OfType<SPListItem>(). SingleOrDefault(i => i.Name == partName); if (item != null) item.Delete(); } }
  • 29. Creating Connectable Web Parts • Pass data from one web part to another • Loosely-coupled connection  Communication managed by WebPartManager  Provider web part supplies data  Consumer web parts retrieve data • Interface used to define data contract  ASP.NET has standard connection contracts  Can use custom connection contracts • SharePoint provides user interface elements to establish connections • Not compatible with sandboxed solutions