360 likes | 560 Views
Advanced Web Part development in SharePoint 2010. Eugene Rosenfeld. About me…. Eugene, MVP, MCAD CTO, Black Blade Associates www.blackbladeinc.com Co-founder, BASPUG www.BostonSharePointUG.org Blogger ThingsThatShouldBeEasy.blogspot.com ERosenfeld@BlackBladeInc.com. Intended Audience.
E N D
Advanced Web Part development in SharePoint 2010 Eugene Rosenfeld
About me… • Eugene, MVP, MCAD • CTO, Black Blade Associateswww.blackbladeinc.com • Co-founder, BASPUGwww.BostonSharePointUG.org • BloggerThingsThatShouldBeEasy.blogspot.com • ERosenfeld@BlackBladeInc.com
Intended Audience • 400-level session • Developers • Mid to senior level • Some SharePoint development experience • Not intended to be an “introduction to SharePoint development” session
Agenda • Introduction • Visual Web Parts • AJAX Web Parts • Web Part Page Services • Sandbox Web Parts • Connections to Service Applications • Multi-platform Web Parts
Introduction • VS 2010 now has direct support for SharePoint 2010 artifact creation • Project Templates • Item templates • Solution packages • “F5” build, deploy, debug experience • Designers, with support for XML customization • NOTE: This is V1
Development Environment • F5 deployment and debugging experience requires SharePoint 2010 on same computer as VS 2010 • SharePoint 2010 is 64-bit only, so dev environment must be a 64-bit OS • Windows Server 2008 or 2008 R2 x64 • Windows 7 x64
Visual Web Parts • Think SmartPart, but better • ASCX design surface • Two code files • User control code file – handles events from ASCX design surface • Real web part – loads the ASCX control as a child control at run time
The Good • Familiar ASCX design experience • All web part files (including ASCX) deployed to appropriate 14 hive folders
The Lacking • Still need lots of code • Handle UI events • Handle Web Part tooling • Data Access • Web Part Properties • Web Part Connections • Added layer of code: ASCX and Web Part • Not compatible with Sandbox Solutions • http://SharepointDevTools.codeplex.com
This demo shows a simple visual web part that also has a visual editor part Visual Web Part with Visual Properties
See how to create a visual web part that will run on SharePoint 2007 using Visual Studio 2008 Visual Web Part for SharePoint 2007
AJAX Web Parts • AJAX is automatically enabled by default • No need to explicitly include a script manager on pages that use AJAX • Three approaches: • ASP.Net AJAX • WPSC • ECMAScript
ASP.Net AJAX • Extends ASP.Net server control model with partial page rendering • Compatible with ASP.Net view state • Easiest way to start with AJAX but very “heavy” model
Web Part Page Services • WPSC: Model that simplifies JavaScript Web Part manipulation • Provides: • Discovery • State Management • Notifications
ECMAScript • Rich model for JavaScript page interaction • Access to • Page • ListView • WebParts • Workflows • Ribbon • Much more
Sandbox Web Parts • Intro Sandboxed Solutions • Sandboxed Solutions Architecture • Restrictions on Sandboxed Code
Intro Sandboxed Solutions • Designed empower site collection admins • Used by • Departments in organizational farms • Hosted site collections in the cloud • Many other multi-tenant scenarios
Sandbox Solutions Architecture • Sandbox code runs in separate process • Sandbox solutions are uploaded to a new site collection gallery • Sandbox solutions have additional restrictions beyond farm solutions
Restrictions on Sandboxed Code • Object model solutions • Data scope restrictions • Artifacts in solution • Code access security • Resource throttling
Connections to Service Applications • Intro to Services Applications • Service Application Architecture
Intro to Services Applications • Evolution of the shared service provider model in SharePoint 2007 • Service applications designed to • Perform long-running operations out side of the web user interface thread • Scale independently of SharePoint web servers • Support cross-farm operations • Potentially invoked from remote farms
Service Application Architecture • Service applications run on configured back-end servers or on other farms • Service application runtime load balances service requests among active service instances • Front-end web servers access services through service proxies
The related contents web part uses the title and description of the current site as the basis for a search query Related Contents Web Part
Web part connections • Connection Model Overview • Connecting to out of the box SharePoint web parts • AJAX Web Part Connections
Connecting to OOTB Web Parts • Connecting to out of the box web parts • Lots of interfaces to implement • Needed interfaces are poorly documented • Interfaces to know: • ListView: IWebPartField, IWebPartRow, IWebPartTable • Filter: IFilterValues
This web part is able to provide data to and consume data from many of the out of the box SharePoint web parts. Connector web part
Multi-platform Web Parts • Platform Detection • Detection Mechanisms • Multi-platform Code
Platform Detection • What are the platforms • WSS V2 / Portal Server 2003 • WSS V3 / Office SharePoint Server 2007 • SharePoint Foundation / SharePoint Server 2010 • Who should care • Product developers • SharePoint hosters • People supporting large deployments
Detection Mechanisms – Object Model • Approach: Try to dynamically load the appropriate SharePoint assembly. Start by loading the higher version numbers first. • Example: • WSS V4 - Microsoft.SharePoint, 14.0.0.0 • MSS 2010 - Microsoft.Office.PortalServer,
Multi-platform Object Model Code • Choice: Use late or early – bound code • Late bound • Don’t need access to each DLL version • No compiler support for error checks • Early bound • Need access to each DLL version • Full compiler support for error checks • Must be careful of where types are declared
Early Bounding Sample private void button1_Click(object sender, System.EventArgs e) { System.Reflection.AssemblyasmWSS; try { //try to load the assembly asmWSS = System.Reflection.Assembly.Load("Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"); } catch(Exception ex) { //the assembly could not load. we assume there is no WSS on this computer asmWSS = null; } if(asmWSS != null) UseWSS(); } private void UseWSS() { //we have a strong reference to an SPSite object Microsoft.SharePoint.SPSite site = new Microsoft.SharePoint.SPSite("http://localhost"); MessageBox.Show(site.GetType().Name.ToString(), "SPSite object created"); }
Late Binding Sample System.Reflection.AssemblyasmWSS; try { asmWSS = System.Reflection.Assembly.Load("Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"); } catch(Exception ex) { //the assembly could not load. we assume there is no WSS on this computer asmWSS = null; } if(asmWSS != null) { //get a late bound reference to the SPSite type //this is equivalent to SPSiteobjSPSite = new SPSite(“http://localhost”); Type typSPSite = asmWSS.GetType("Microsoft.SharePoint.SPSite"); //get a reference to the constructor for SPSite that has this signature: // new Microsoft.SharePoint.SPSite("http://localhost") // and invoke the constructor object objSPSite = typSPSite.GetConstructor(new Type[]{ typeof(string) }).Invoke(new object[]{ "http://localhost" }); }
This web part can run on both versions of SharePoint 2010 and take advantage of the features of each platform. Multi-platform web part
Additional Resources • AJAX – Jan Tielens • http://www.bing.com/search?q=site%3Ahttp%3A%2F%2Fweblogs.asp.net+jan+sharepoint+jquery • Multi-platform Code – Black Blade • http://www.blackbladeinc.com/en-us/community/Pages/Speaking.aspx
Thank you for attending! Eugene Rosenfeld @erosen03 ThingsThatShouldBeEasy.blogspot.com ERosenfeld@BlackBladeInc.com