SlideShare a Scribd company logo
Advanced SharePoint Web Part Development
Rob Windsor
rob@robwindsor.com
@robwindsor
About Me
 Senior SharePoint Consultant
 Technical Contributor to the Pluralsight On-Demand Library
 Microsoft MVP, MCPD, MCT
 Founder and Past-President of the North Toronto .NET UG
 Co-author of Prof. Visual Basic 2012 and .NET 4.5 (Wrox)
Session Prerequisites
 Experience developing for SharePoint
 Experience building Web Parts
 Experience with JavaScript and jQuery
Agenda
 Script Parts
 Persistent Web Part Properties
 Editor Parts
 Script Part Properties
 Connectable Web Parts
 Asynchronous Web Parts
 Web Part Gallery
 Web Part Pages
DEMO
Basic Web Parts
Script Parts
 Web parts implemented using only JavaScript
 Why?
 Can’t deploy farm solutions to SharePoint Online
 Sandbox solutions with managed code are deprecated
 Restrictions
 Can’t create custom web parts without managed code
 Must use OOB web parts to implement script parts
 Implementation
 Use modules to provision JavaScript/HTML files
 Use custom actions to load common JavaScript files
 Use Content Editor Web Part to inject HTML and JavaScript into page
DEMO
Script Part
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
Editor Parts
 Editor parts enable user customization
 Editor parts contained within an editor
zone
 ASP.NET supplies standard editor parts
 Layout, appearance, etc
 Developers can create custom editor
parts
 Similar development experience to Web Part
 Control over interface used to edit properties
 Ability to validate user input
 In web part
 Override CreateEditorParts
 In editor part
 Override CreateChildControls, SyncChanges and
ApplyChanges
DEMO
Editor Parts
Script Part Properties
 No way to implement real web part properties without managed code
 We can emulate the user experience
 Property values stored in element attribute
 Detect when property editor is open
 Add data entry controls into editor using jQuery
 Capture submit event and retrieve values
 Update attribute containing property values
 Use native script editor web part persistence mechanism
 Alternative implementation
 Build Custom Web Part Properties with JSOM
 vxcompany.com/kennis/blog/2014/10/02/build-custom-web-part-properties-jsom/
DEMO
Script Part Properties
IMPORTANT: This demo is a
proof of concept only. It is
nowhere near production
ready!
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
 Shown later in this module
 Can use custom connection contracts
 SharePoint provides user interface elements to establish
connections
 Not compatible with sandboxed solutions
DEMO
Web Part Connections
Web Part Connections using Ajax
 Communication between web parts requires a postback
 Generally, only consumer web part needs to be updated
 Can use partial page rendering (UpdatePanel) to only update
consumer
 Problem:
 Event triggered by provider
 UpdatePanel in consumer
 Solution:
 Pass reference to control that triggers update from provider to consumer
 Consumer registers control as AsyncPostbackControl with
ScriptManager
DEMO
Web Part Connections
Using Ajax
Asynchronous Loading of Web Parts
 Long running tasks are blocking calls
 One web part can bring a page to a crawl
 When on the same page, multiple instances can kill the user experience
 Make long running tasks asynchronous
 Don’t hold up page processing
Asynchronous Loading of Web Parts
protected void Page_PreRender(object sender, EventArgs e) {
_func = new Func<XDocument>(GetFeed);
Page.RegisterAsyncTask(
new PageAsyncTask(
new BeginEventHandler(BeginFeed),
new EndEventHandler(EndFeed),
new EndEventHandler(TimoutFeed),
null, true));
}
public IAsyncResult BeginFeed(object sender, EventArgs e, AsyncCallback cb, object state) {
return _func.BeginInvoke(cb, state);
}
public void EndFeed(IAsyncResult ar) {
var feed = _func.EndInvoke(ar);
var posts = from item in feed.Descendants("item")
select new {
Title = item.Element("title").Value,
Description = item.Element("description").Value,
Published = DateTime.Parse(item.Element("pubDate").Value)
};
posts = posts.Skip(_pageNum * PageSize).Take(PageSize);
FeedListView.DataSource = posts.ToList();
FeedListView.DataBind();
}
DEMO
Async Loading of Web
Parts
Minimal Download Strategy
 All controls on a page must be marked as MdsCompliant for
page to use Minimal Download Strategy
 MdsCompliant Restrictions:
 HTML style and script tags are not supported
 Use CssRegistration and ScriptLink instead
 Using Response object to write to page is not supported
 Use SPHttpUtility.Write* instead
 Inline code must be wrapped in SharePoint:ScriptBlock element
 For more information see Modify SharePoint components for MDS
 http://msdn.microsoft.com/library/office/dn456543.aspx
DEMO
MdsCompliant
Cleaning the Web Part Gallery
 Files provisioned into Content DB do not get removed on
Feature deactivation
 This includes webpart / dwp files added to Web Part Gallery
 Deletion of files can be done in Feature receiver
 Examine element manifests to find web parts
 Remove from web part gallery
Cleaning the Web Part Gallery
public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
var site = properties.Feature.Parent as SPSite;
if (site == null) return;
var parts = new List<string>();
var elements = properties.Definition.GetElementDefinitions(CultureInfo.CurrentCulture);
foreach (SPElementDefinition element in elements) {
if (element.ElementType != "Module") continue;
var node = element.XmlDefinition;
if (node.Attributes["Url"].Value != "_catalogs/wp") continue;
foreach (XmlElement childNode in node.ChildNodes) {
if (childNode.Name == "File") {
parts.Add(childNode.GetAttribute("Url"));
}
}
}
var web = site.RootWeb;
var gallery = web.Lists["Web Part Gallery"];
var items = gallery.Items;
for (int i = items.Count - 1; i >= 0; i--) {
var item = items[i];
if (parts.Contains(item.File.Name)) {
item.Delete();
}
}
}
DEMO
Cleaning the Web Part
Gallery
Creating Web Part Page Templates
 Create a site page
 Set base type to
Microsoft.SharePoint.WebPartPages.WebPartPage
 Add one or more web part zones to page
 Provision page instances using Module
<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<!-- Other register directives -->
<%@ Register Tagprefix="WebPartPages"
Namespace="Microsoft.SharePoint.WebPartPages"
Assembly="Microsoft.SharePoint, Version=14.0.0.0, …" %>
<%@ Page Language="C#"
Inherits="Microsoft.SharePoint.WebPartPages.WebPartPage"
MasterPageFile="~masterurl/default.master" %>
<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<WebPartPages:WebPartZone
ID="MainZone" runat="server"
FrameType="TitleBarOnly"
Title="Main Web Part Zone" />
</asp:Content>
Adding Web Parts to Web Part Pages
 Use SPLimitedWebPartManager
 Get reference from property of Page object
 Use SPLimitedWebPartManager.AddWebPart to add
var page = web.GetFile("SiteAssets/Test02.aspx");
using (var manager = page.GetLimitedWebPartManager(
PersonalizationScope.Shared)) {
if (!manager.WebParts.Contains(webPartTitle))
{
var part = new MostPopularProducts2.MostPopularProducts2();
part.Title = "Most Popular Products";
part.Category = "Condiments";
part.Year = 1997;
manager.AddWebPart(part, "Left", 0);
}
}
Note: Contains method shown in code sample is a custom extension
DEMO
Creating Web Part Pages
and Adding Web Parts
Additional Stuff
 Closing versus deleting web parts
 Closing a web part does not remove it from page
 Having many closed web parts on a page can degrade performance
 Set AllowClose to false to remove option to close from web part verbs
 Versioning
 DO NOT change the assembly version of your assemblies
 SharePoint stores the full name with version of all web parts in galleries
and on pages
 Use the AssemblyFileVersion instead
Thank You
 Big thanks to the organizers, sponsors and you for
making this event possible
 Please fill out your evaluation
 Please keep in touch
rob@robwindsor.com
@robwindsor
msmvps.com/blogs/windsor
Ad

More Related Content

What's hot (20)

JavaScript and jQuery for SharePoint Developers
JavaScript and jQuery for SharePoint DevelopersJavaScript and jQuery for SharePoint Developers
JavaScript and jQuery for SharePoint Developers
Rob Windsor
 
Understanding and programming the SharePoint REST API
Understanding and programming the SharePoint REST APIUnderstanding and programming the SharePoint REST API
Understanding and programming the SharePoint REST API
Chris Beckett
 
Develop iOS and Android apps with SharePoint/Office 365
Develop iOS and Android apps with SharePoint/Office 365Develop iOS and Android apps with SharePoint/Office 365
Develop iOS and Android apps with SharePoint/Office 365
Kashif Imran
 
Introduction to the SharePoint 2013 REST API
Introduction to the SharePoint 2013 REST APIIntroduction to the SharePoint 2013 REST API
Introduction to the SharePoint 2013 REST API
Sparkhound Inc.
 
Taking Advantage of the SharePoint 2013 REST API
Taking Advantage of the SharePoint 2013 REST APITaking Advantage of the SharePoint 2013 REST API
Taking Advantage of the SharePoint 2013 REST API
Eric Shupps
 
Are you getting Sleepy. REST in SharePoint Apps
Are you getting Sleepy. REST in SharePoint AppsAre you getting Sleepy. REST in SharePoint Apps
Are you getting Sleepy. REST in SharePoint Apps
Liam Cleary [MVP]
 
Sharepoint Online
Sharepoint OnlineSharepoint Online
Sharepoint Online
Shakir Majeed Khan
 
Asp.net.
Asp.net.Asp.net.
Asp.net.
Naveen Sihag
 
SharePoint 2013 REST API & Remote Authentication
SharePoint 2013 REST API & Remote AuthenticationSharePoint 2013 REST API & Remote Authentication
SharePoint 2013 REST API & Remote Authentication
Adil Ansari
 
SharePoint 2013 APIs
SharePoint 2013 APIsSharePoint 2013 APIs
SharePoint 2013 APIs
John Calvert
 
Who Are You and What Do You Want? Working with OAuth in SharePoint 2013.
Who Are You and What Do You Want? Working with OAuth in SharePoint 2013.Who Are You and What Do You Want? Working with OAuth in SharePoint 2013.
Who Are You and What Do You Want? Working with OAuth in SharePoint 2013.
Eric Shupps
 
CSOM (Client Side Object Model). Explained @ SharePoint Saturday Houston
CSOM (Client Side Object Model). Explained @ SharePoint Saturday HoustonCSOM (Client Side Object Model). Explained @ SharePoint Saturday Houston
CSOM (Client Side Object Model). Explained @ SharePoint Saturday Houston
Kunaal Kapoor
 
Toms introtospring mvc
Toms introtospring mvcToms introtospring mvc
Toms introtospring mvc
Guo Albert
 
Working With Sharepoint 2013 Apps Development
Working With Sharepoint 2013 Apps DevelopmentWorking With Sharepoint 2013 Apps Development
Working With Sharepoint 2013 Apps Development
Pankaj Srivastava
 
Ch 04 asp.net application
Ch 04 asp.net application Ch 04 asp.net application
Ch 04 asp.net application
Madhuri Kavade
 
Server Controls of ASP.Net
Server Controls of ASP.NetServer Controls of ASP.Net
Server Controls of ASP.Net
Hitesh Santani
 
SPTechCon 2014 How to develop and debug client side code in SharePoint
SPTechCon 2014 How to develop and debug client side code in SharePointSPTechCon 2014 How to develop and debug client side code in SharePoint
SPTechCon 2014 How to develop and debug client side code in SharePoint
Mark Rackley
 
Introduction to using jQuery with SharePoint
Introduction to using jQuery with SharePointIntroduction to using jQuery with SharePoint
Introduction to using jQuery with SharePoint
Rene Modery
 
ASP.NET Overview - Alvin Lau
ASP.NET Overview - Alvin LauASP.NET Overview - Alvin Lau
ASP.NET Overview - Alvin Lau
Spiffy
 
Office 2013 loves web developers slide
Office 2013 loves web developers   slideOffice 2013 loves web developers   slide
Office 2013 loves web developers slide
Fabio Franzini
 
JavaScript and jQuery for SharePoint Developers
JavaScript and jQuery for SharePoint DevelopersJavaScript and jQuery for SharePoint Developers
JavaScript and jQuery for SharePoint Developers
Rob Windsor
 
Understanding and programming the SharePoint REST API
Understanding and programming the SharePoint REST APIUnderstanding and programming the SharePoint REST API
Understanding and programming the SharePoint REST API
Chris Beckett
 
Develop iOS and Android apps with SharePoint/Office 365
Develop iOS and Android apps with SharePoint/Office 365Develop iOS and Android apps with SharePoint/Office 365
Develop iOS and Android apps with SharePoint/Office 365
Kashif Imran
 
Introduction to the SharePoint 2013 REST API
Introduction to the SharePoint 2013 REST APIIntroduction to the SharePoint 2013 REST API
Introduction to the SharePoint 2013 REST API
Sparkhound Inc.
 
Taking Advantage of the SharePoint 2013 REST API
Taking Advantage of the SharePoint 2013 REST APITaking Advantage of the SharePoint 2013 REST API
Taking Advantage of the SharePoint 2013 REST API
Eric Shupps
 
Are you getting Sleepy. REST in SharePoint Apps
Are you getting Sleepy. REST in SharePoint AppsAre you getting Sleepy. REST in SharePoint Apps
Are you getting Sleepy. REST in SharePoint Apps
Liam Cleary [MVP]
 
SharePoint 2013 REST API & Remote Authentication
SharePoint 2013 REST API & Remote AuthenticationSharePoint 2013 REST API & Remote Authentication
SharePoint 2013 REST API & Remote Authentication
Adil Ansari
 
SharePoint 2013 APIs
SharePoint 2013 APIsSharePoint 2013 APIs
SharePoint 2013 APIs
John Calvert
 
Who Are You and What Do You Want? Working with OAuth in SharePoint 2013.
Who Are You and What Do You Want? Working with OAuth in SharePoint 2013.Who Are You and What Do You Want? Working with OAuth in SharePoint 2013.
Who Are You and What Do You Want? Working with OAuth in SharePoint 2013.
Eric Shupps
 
CSOM (Client Side Object Model). Explained @ SharePoint Saturday Houston
CSOM (Client Side Object Model). Explained @ SharePoint Saturday HoustonCSOM (Client Side Object Model). Explained @ SharePoint Saturday Houston
CSOM (Client Side Object Model). Explained @ SharePoint Saturday Houston
Kunaal Kapoor
 
Toms introtospring mvc
Toms introtospring mvcToms introtospring mvc
Toms introtospring mvc
Guo Albert
 
Working With Sharepoint 2013 Apps Development
Working With Sharepoint 2013 Apps DevelopmentWorking With Sharepoint 2013 Apps Development
Working With Sharepoint 2013 Apps Development
Pankaj Srivastava
 
Ch 04 asp.net application
Ch 04 asp.net application Ch 04 asp.net application
Ch 04 asp.net application
Madhuri Kavade
 
Server Controls of ASP.Net
Server Controls of ASP.NetServer Controls of ASP.Net
Server Controls of ASP.Net
Hitesh Santani
 
SPTechCon 2014 How to develop and debug client side code in SharePoint
SPTechCon 2014 How to develop and debug client side code in SharePointSPTechCon 2014 How to develop and debug client side code in SharePoint
SPTechCon 2014 How to develop and debug client side code in SharePoint
Mark Rackley
 
Introduction to using jQuery with SharePoint
Introduction to using jQuery with SharePointIntroduction to using jQuery with SharePoint
Introduction to using jQuery with SharePoint
Rene Modery
 
ASP.NET Overview - Alvin Lau
ASP.NET Overview - Alvin LauASP.NET Overview - Alvin Lau
ASP.NET Overview - Alvin Lau
Spiffy
 
Office 2013 loves web developers slide
Office 2013 loves web developers   slideOffice 2013 loves web developers   slide
Office 2013 loves web developers slide
Fabio Franzini
 

Similar to Advanced SharePoint Web Part Development (20)

Tutorial, Part 4: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
Tutorial, Part 4: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...Tutorial, Part 4: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
Tutorial, Part 4: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
SPTechCon
 
Asp.net By Durgesh Singh
Asp.net By Durgesh SinghAsp.net By Durgesh Singh
Asp.net By Durgesh Singh
imdurgesh
 
SharePoint Object Model, Web Services and Events
SharePoint Object Model, Web Services and EventsSharePoint Object Model, Web Services and Events
SharePoint Object Model, Web Services and Events
Mohan Arumugam
 
Apache Wicket Web Framework
Apache Wicket Web FrameworkApache Wicket Web Framework
Apache Wicket Web Framework
Luther Baker
 
SharePoint Development with the SharePoint Framework
SharePoint Development with the SharePoint FrameworkSharePoint Development with the SharePoint Framework
SharePoint Development with the SharePoint Framework
JoAnna Cheshire
 
Asp.Net Ajax Component Development
Asp.Net Ajax Component DevelopmentAsp.Net Ajax Component Development
Asp.Net Ajax Component Development
Chui-Wen Chiu
 
Intro react js
Intro react jsIntro react js
Intro react js
Vijayakanth MP
 
ASP.NET Lecture 1
ASP.NET Lecture 1ASP.NET Lecture 1
ASP.NET Lecture 1
Julie Iskander
 
Web Components v1
Web Components v1Web Components v1
Web Components v1
Mike Wilcox
 
Web driver training
Web driver trainingWeb driver training
Web driver training
Dipesh Bhatewara
 
OttawaJS - React
OttawaJS - ReactOttawaJS - React
OttawaJS - React
rbl002
 
Creating Web Parts New
Creating Web Parts NewCreating Web Parts New
Creating Web Parts New
LiquidHub
 
Creating Web Parts New
Creating Web Parts NewCreating Web Parts New
Creating Web Parts New
LiquidHub
 
Creating Web Parts New
Creating Web Parts NewCreating Web Parts New
Creating Web Parts New
LiquidHub
 
Parallelminds.web partdemo1
Parallelminds.web partdemo1Parallelminds.web partdemo1
Parallelminds.web partdemo1
parallelminder
 
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Roy de Kleijn
 
Spicing up SharePoint web parts
Spicing up SharePoint web partsSpicing up SharePoint web parts
Spicing up SharePoint web parts
Randy Williams
 
Customizing Oracle EBS OA Framework
Customizing Oracle EBS OA FrameworkCustomizing Oracle EBS OA Framework
Customizing Oracle EBS OA Framework
iWare Logic Technologies Pvt. Ltd.
 
ASP.NET Lecture 6
ASP.NET Lecture 6ASP.NET Lecture 6
ASP.NET Lecture 6
Julie Iskander
 
ASP.NET - Web Programming
ASP.NET - Web ProgrammingASP.NET - Web Programming
ASP.NET - Web Programming
baabtra.com - No. 1 supplier of quality freshers
 
Tutorial, Part 4: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
Tutorial, Part 4: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...Tutorial, Part 4: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
Tutorial, Part 4: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
SPTechCon
 
Asp.net By Durgesh Singh
Asp.net By Durgesh SinghAsp.net By Durgesh Singh
Asp.net By Durgesh Singh
imdurgesh
 
SharePoint Object Model, Web Services and Events
SharePoint Object Model, Web Services and EventsSharePoint Object Model, Web Services and Events
SharePoint Object Model, Web Services and Events
Mohan Arumugam
 
Apache Wicket Web Framework
Apache Wicket Web FrameworkApache Wicket Web Framework
Apache Wicket Web Framework
Luther Baker
 
SharePoint Development with the SharePoint Framework
SharePoint Development with the SharePoint FrameworkSharePoint Development with the SharePoint Framework
SharePoint Development with the SharePoint Framework
JoAnna Cheshire
 
Asp.Net Ajax Component Development
Asp.Net Ajax Component DevelopmentAsp.Net Ajax Component Development
Asp.Net Ajax Component Development
Chui-Wen Chiu
 
Web Components v1
Web Components v1Web Components v1
Web Components v1
Mike Wilcox
 
OttawaJS - React
OttawaJS - ReactOttawaJS - React
OttawaJS - React
rbl002
 
Creating Web Parts New
Creating Web Parts NewCreating Web Parts New
Creating Web Parts New
LiquidHub
 
Creating Web Parts New
Creating Web Parts NewCreating Web Parts New
Creating Web Parts New
LiquidHub
 
Creating Web Parts New
Creating Web Parts NewCreating Web Parts New
Creating Web Parts New
LiquidHub
 
Parallelminds.web partdemo1
Parallelminds.web partdemo1Parallelminds.web partdemo1
Parallelminds.web partdemo1
parallelminder
 
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Roy de Kleijn
 
Spicing up SharePoint web parts
Spicing up SharePoint web partsSpicing up SharePoint web parts
Spicing up SharePoint web parts
Randy Williams
 
Ad

Recently uploaded (20)

Buckeye Dreamin' 2023: De-fogging Debug Logs
Buckeye Dreamin' 2023: De-fogging Debug LogsBuckeye Dreamin' 2023: De-fogging Debug Logs
Buckeye Dreamin' 2023: De-fogging Debug Logs
Lynda Kane
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
"Client Partnership — the Path to Exponential Growth for Companies Sized 50-5...
"Client Partnership — the Path to Exponential Growth for Companies Sized 50-5..."Client Partnership — the Path to Exponential Growth for Companies Sized 50-5...
"Client Partnership — the Path to Exponential Growth for Companies Sized 50-5...
Fwdays
 
Buckeye Dreamin 2024: Assessing and Resolving Technical Debt
Buckeye Dreamin 2024: Assessing and Resolving Technical DebtBuckeye Dreamin 2024: Assessing and Resolving Technical Debt
Buckeye Dreamin 2024: Assessing and Resolving Technical Debt
Lynda Kane
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Datastucture-Unit 4-Linked List Presentation.pptx
Datastucture-Unit 4-Linked List Presentation.pptxDatastucture-Unit 4-Linked List Presentation.pptx
Datastucture-Unit 4-Linked List Presentation.pptx
kaleeswaric3
 
"Rebranding for Growth", Anna Velykoivanenko
"Rebranding for Growth", Anna Velykoivanenko"Rebranding for Growth", Anna Velykoivanenko
"Rebranding for Growth", Anna Velykoivanenko
Fwdays
 
Automation Dreamin': Capture User Feedback From Anywhere
Automation Dreamin': Capture User Feedback From AnywhereAutomation Dreamin': Capture User Feedback From Anywhere
Automation Dreamin': Capture User Feedback From Anywhere
Lynda Kane
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
Leading AI Innovation As A Product Manager - Michael Jidael
Leading AI Innovation As A Product Manager - Michael JidaelLeading AI Innovation As A Product Manager - Michael Jidael
Leading AI Innovation As A Product Manager - Michael Jidael
Michael Jidael
 
Automation Hour 1/28/2022: Capture User Feedback from Anywhere
Automation Hour 1/28/2022: Capture User Feedback from AnywhereAutomation Hour 1/28/2022: Capture User Feedback from Anywhere
Automation Hour 1/28/2022: Capture User Feedback from Anywhere
Lynda Kane
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Salesforce AI Associate 2 of 2 Certification.docx
Salesforce AI Associate 2 of 2 Certification.docxSalesforce AI Associate 2 of 2 Certification.docx
Salesforce AI Associate 2 of 2 Certification.docx
José Enrique López Rivera
 
Image processinglab image processing image processing
Image processinglab image processing  image processingImage processinglab image processing  image processing
Image processinglab image processing image processing
RaghadHany
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Rock, Paper, Scissors: An Apex Map Learning Journey
Rock, Paper, Scissors: An Apex Map Learning JourneyRock, Paper, Scissors: An Apex Map Learning Journey
Rock, Paper, Scissors: An Apex Map Learning Journey
Lynda Kane
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Buckeye Dreamin' 2023: De-fogging Debug Logs
Buckeye Dreamin' 2023: De-fogging Debug LogsBuckeye Dreamin' 2023: De-fogging Debug Logs
Buckeye Dreamin' 2023: De-fogging Debug Logs
Lynda Kane
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
"Client Partnership — the Path to Exponential Growth for Companies Sized 50-5...
"Client Partnership — the Path to Exponential Growth for Companies Sized 50-5..."Client Partnership — the Path to Exponential Growth for Companies Sized 50-5...
"Client Partnership — the Path to Exponential Growth for Companies Sized 50-5...
Fwdays
 
Buckeye Dreamin 2024: Assessing and Resolving Technical Debt
Buckeye Dreamin 2024: Assessing and Resolving Technical DebtBuckeye Dreamin 2024: Assessing and Resolving Technical Debt
Buckeye Dreamin 2024: Assessing and Resolving Technical Debt
Lynda Kane
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Datastucture-Unit 4-Linked List Presentation.pptx
Datastucture-Unit 4-Linked List Presentation.pptxDatastucture-Unit 4-Linked List Presentation.pptx
Datastucture-Unit 4-Linked List Presentation.pptx
kaleeswaric3
 
"Rebranding for Growth", Anna Velykoivanenko
"Rebranding for Growth", Anna Velykoivanenko"Rebranding for Growth", Anna Velykoivanenko
"Rebranding for Growth", Anna Velykoivanenko
Fwdays
 
Automation Dreamin': Capture User Feedback From Anywhere
Automation Dreamin': Capture User Feedback From AnywhereAutomation Dreamin': Capture User Feedback From Anywhere
Automation Dreamin': Capture User Feedback From Anywhere
Lynda Kane
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
Leading AI Innovation As A Product Manager - Michael Jidael
Leading AI Innovation As A Product Manager - Michael JidaelLeading AI Innovation As A Product Manager - Michael Jidael
Leading AI Innovation As A Product Manager - Michael Jidael
Michael Jidael
 
Automation Hour 1/28/2022: Capture User Feedback from Anywhere
Automation Hour 1/28/2022: Capture User Feedback from AnywhereAutomation Hour 1/28/2022: Capture User Feedback from Anywhere
Automation Hour 1/28/2022: Capture User Feedback from Anywhere
Lynda Kane
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Salesforce AI Associate 2 of 2 Certification.docx
Salesforce AI Associate 2 of 2 Certification.docxSalesforce AI Associate 2 of 2 Certification.docx
Salesforce AI Associate 2 of 2 Certification.docx
José Enrique López Rivera
 
Image processinglab image processing image processing
Image processinglab image processing  image processingImage processinglab image processing  image processing
Image processinglab image processing image processing
RaghadHany
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Rock, Paper, Scissors: An Apex Map Learning Journey
Rock, Paper, Scissors: An Apex Map Learning JourneyRock, Paper, Scissors: An Apex Map Learning Journey
Rock, Paper, Scissors: An Apex Map Learning Journey
Lynda Kane
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Ad

Advanced SharePoint Web Part Development

  • 1. Advanced SharePoint Web Part Development Rob Windsor [email protected] @robwindsor
  • 2. About Me  Senior SharePoint Consultant  Technical Contributor to the Pluralsight On-Demand Library  Microsoft MVP, MCPD, MCT  Founder and Past-President of the North Toronto .NET UG  Co-author of Prof. Visual Basic 2012 and .NET 4.5 (Wrox)
  • 3. Session Prerequisites  Experience developing for SharePoint  Experience building Web Parts  Experience with JavaScript and jQuery
  • 4. Agenda  Script Parts  Persistent Web Part Properties  Editor Parts  Script Part Properties  Connectable Web Parts  Asynchronous Web Parts  Web Part Gallery  Web Part Pages
  • 6. Script Parts  Web parts implemented using only JavaScript  Why?  Can’t deploy farm solutions to SharePoint Online  Sandbox solutions with managed code are deprecated  Restrictions  Can’t create custom web parts without managed code  Must use OOB web parts to implement script parts  Implementation  Use modules to provision JavaScript/HTML files  Use custom actions to load common JavaScript files  Use Content Editor Web Part to inject HTML and JavaScript into page
  • 8. 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; }
  • 10. Editor Parts  Editor parts enable user customization  Editor parts contained within an editor zone  ASP.NET supplies standard editor parts  Layout, appearance, etc  Developers can create custom editor parts  Similar development experience to Web Part  Control over interface used to edit properties  Ability to validate user input  In web part  Override CreateEditorParts  In editor part  Override CreateChildControls, SyncChanges and ApplyChanges
  • 12. Script Part Properties  No way to implement real web part properties without managed code  We can emulate the user experience  Property values stored in element attribute  Detect when property editor is open  Add data entry controls into editor using jQuery  Capture submit event and retrieve values  Update attribute containing property values  Use native script editor web part persistence mechanism  Alternative implementation  Build Custom Web Part Properties with JSOM  vxcompany.com/kennis/blog/2014/10/02/build-custom-web-part-properties-jsom/
  • 13. DEMO Script Part Properties IMPORTANT: This demo is a proof of concept only. It is nowhere near production ready!
  • 14. 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  Shown later in this module  Can use custom connection contracts  SharePoint provides user interface elements to establish connections  Not compatible with sandboxed solutions
  • 16. Web Part Connections using Ajax  Communication between web parts requires a postback  Generally, only consumer web part needs to be updated  Can use partial page rendering (UpdatePanel) to only update consumer  Problem:  Event triggered by provider  UpdatePanel in consumer  Solution:  Pass reference to control that triggers update from provider to consumer  Consumer registers control as AsyncPostbackControl with ScriptManager
  • 18. Asynchronous Loading of Web Parts  Long running tasks are blocking calls  One web part can bring a page to a crawl  When on the same page, multiple instances can kill the user experience  Make long running tasks asynchronous  Don’t hold up page processing
  • 19. Asynchronous Loading of Web Parts protected void Page_PreRender(object sender, EventArgs e) { _func = new Func<XDocument>(GetFeed); Page.RegisterAsyncTask( new PageAsyncTask( new BeginEventHandler(BeginFeed), new EndEventHandler(EndFeed), new EndEventHandler(TimoutFeed), null, true)); } public IAsyncResult BeginFeed(object sender, EventArgs e, AsyncCallback cb, object state) { return _func.BeginInvoke(cb, state); } public void EndFeed(IAsyncResult ar) { var feed = _func.EndInvoke(ar); var posts = from item in feed.Descendants("item") select new { Title = item.Element("title").Value, Description = item.Element("description").Value, Published = DateTime.Parse(item.Element("pubDate").Value) }; posts = posts.Skip(_pageNum * PageSize).Take(PageSize); FeedListView.DataSource = posts.ToList(); FeedListView.DataBind(); }
  • 21. Minimal Download Strategy  All controls on a page must be marked as MdsCompliant for page to use Minimal Download Strategy  MdsCompliant Restrictions:  HTML style and script tags are not supported  Use CssRegistration and ScriptLink instead  Using Response object to write to page is not supported  Use SPHttpUtility.Write* instead  Inline code must be wrapped in SharePoint:ScriptBlock element  For more information see Modify SharePoint components for MDS  http://msdn.microsoft.com/library/office/dn456543.aspx
  • 23. Cleaning the Web Part Gallery  Files provisioned into Content DB do not get removed on Feature deactivation  This includes webpart / dwp files added to Web Part Gallery  Deletion of files can be done in Feature receiver  Examine element manifests to find web parts  Remove from web part gallery
  • 24. Cleaning the Web Part Gallery public override void FeatureDeactivating(SPFeatureReceiverProperties properties) { var site = properties.Feature.Parent as SPSite; if (site == null) return; var parts = new List<string>(); var elements = properties.Definition.GetElementDefinitions(CultureInfo.CurrentCulture); foreach (SPElementDefinition element in elements) { if (element.ElementType != "Module") continue; var node = element.XmlDefinition; if (node.Attributes["Url"].Value != "_catalogs/wp") continue; foreach (XmlElement childNode in node.ChildNodes) { if (childNode.Name == "File") { parts.Add(childNode.GetAttribute("Url")); } } } var web = site.RootWeb; var gallery = web.Lists["Web Part Gallery"]; var items = gallery.Items; for (int i = items.Count - 1; i >= 0; i--) { var item = items[i]; if (parts.Contains(item.File.Name)) { item.Delete(); } } }
  • 25. DEMO Cleaning the Web Part Gallery
  • 26. Creating Web Part Page Templates  Create a site page  Set base type to Microsoft.SharePoint.WebPartPages.WebPartPage  Add one or more web part zones to page  Provision page instances using Module <%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %> <!-- Other register directives --> <%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, …" %> <%@ Page Language="C#" Inherits="Microsoft.SharePoint.WebPartPages.WebPartPage" MasterPageFile="~masterurl/default.master" %> <asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server"> <WebPartPages:WebPartZone ID="MainZone" runat="server" FrameType="TitleBarOnly" Title="Main Web Part Zone" /> </asp:Content>
  • 27. Adding Web Parts to Web Part Pages  Use SPLimitedWebPartManager  Get reference from property of Page object  Use SPLimitedWebPartManager.AddWebPart to add var page = web.GetFile("SiteAssets/Test02.aspx"); using (var manager = page.GetLimitedWebPartManager( PersonalizationScope.Shared)) { if (!manager.WebParts.Contains(webPartTitle)) { var part = new MostPopularProducts2.MostPopularProducts2(); part.Title = "Most Popular Products"; part.Category = "Condiments"; part.Year = 1997; manager.AddWebPart(part, "Left", 0); } } Note: Contains method shown in code sample is a custom extension
  • 28. DEMO Creating Web Part Pages and Adding Web Parts
  • 29. Additional Stuff  Closing versus deleting web parts  Closing a web part does not remove it from page  Having many closed web parts on a page can degrade performance  Set AllowClose to false to remove option to close from web part verbs  Versioning  DO NOT change the assembly version of your assemblies  SharePoint stores the full name with version of all web parts in galleries and on pages  Use the AssemblyFileVersion instead
  • 30. Thank You  Big thanks to the organizers, sponsors and you for making this event possible  Please fill out your evaluation  Please keep in touch [email protected] @robwindsor msmvps.com/blogs/windsor

Editor's Notes