SharePoint 2013 DEV. David Čamdžić Kompas Xnet d.o.o.

Size: px
Start display at page:

Download "SharePoint 2013 DEV. David Čamdžić Kompas Xnet d.o.o."

Transcription

1 SharePoint 2013 DEV David Čamdžić Kompas Xnet d.o.o.

2 David Čamdžić Sharepoint Solutions developer since 2007 on and off Developing mostly intranet SharePoint solutions Currently working on about 10 Sharepoint projects Programming in C# and JavaScript/TypeScript.NET Developer since 2004

3 SharePoint 2013 development best practices History of SharePoint Development SharePoint API types CSOM/REST interfaces Add-in model Full Trust Solutions

4 History of SharePoint Development SharePoint Portal Server 2001 SharePoint Team Services 2002 SharePoint Portal Server 2003.NET 1.1 Solutions Custom web parts Pre-defined WF Web Services

5 History of SharePoint Development Microsoft Office SharePoint Server 2007 Solution Packages Custom Workflow via WWF and SPD CAS

6 History of SharePoint Development Microsoft SharePoint Server 2010 Sandbox (Partial Trust) CSOM REST JQuery and Silverlight support Powershell

7 What do we have so far? Full trust often Breakable Farms Code Access Security (CAS) not used since SP 2010 Poor testing Sandbox limitations CSOM and JQuery allow some slick results

8 Parallel Developments in Cloud Microsoft-hosted SharePoint Business Productivity Online Standard Suite Office 365 Beta Transitioning Office 365 Tenancies to SharePoint 2013 brings App Model

9 SharePoint 2013 Microsoft SharePoint Server 2013 Add-in Model, new CSOM and REST interfaces Cloud, cloud, cloud Full Trust Solutions

10 SharePoint 2013 From

11 SharePoint No-No's Instantiating an SPSite object inside an event receiver: // Bad Coding Practice public override void ItemDeleting(SPItemEventProperties props) { using (SPSite site = new SPSite(props.WebUrl)) using (SPWeb web = site.openweb()) { SPList list = web.lists[props.listid]; SPListItem item = list.getitembyuniqueid(props.listitemid); } } // Good Coding Practice public override void ItemDeleting(SPItemEventProperties props) { using (SPSite site = new SPSite(props.WebUrl)) using (SPWeb web = site.openweb()) { SPList list = web.lists[props.listid]; SPListItem item = list.getitembyuniqueid(props.listitemid); } }

12 SharePoint No-No's Enumerating over SPList.Items or SPFolder.Files use SPList.GetItems(SPQuery) instead of enumerating list items // Bad Coding Practice foreach (SPListItem item in list.items) {... } // Good Coding Practice SPQuery query = new SPQuery(); SPListItemCollection listitems = list.getitems(query); foreach (SPListItem item in listitems) {... }

13 SharePoint No-No's Deleting multiple versions of a list item // Bad Coding Practice SPList list = web.lists["custom list name"]; SPListItem item = list.getitembyid(1); SPListItemVersionCollection vcollection = item.versions; ArrayList idlist = new ArrayList(); foreach(splistitemversion ver in vcollection) { idlist.add(ver.versionid); } foreach(int verid in idlist) { SPListItemVersion version = vcollection.getversionfromid(verid); version.delete(); } // Good Coding Practice SPList list = web.lists["custom list name"]; SPListItem item = list.getitembyid(1); SPFile file = web.getfile(item.url); SPFileVersionCollection collection = file.versions; ArrayList idlist = new ArrayList(); foreach (SPFileVersion ver in collection) { idlist.add(ver.id); } foreach (int verid in idlist) { collection.deletebyid(verid); }

14 SharePoint No-No's Using unbounded SPQuery objects An SPQuery object without a value for RowLimit will perform poorly and fail on large lists. Specify a RowLimit between 1 and 2000 and, if necessary, page through the list. If you query on a field that is not indexed, the query will be blocked whenever it would result in a scan of more items than the query threshold (as soon as there are more items in the list than are specified in the query threshold). Set SPQuery.RowLimit to a value that is less than the query threshold. If you know the URL of your list item and want to query by FileRef, use SPWeb.GetListItem(string strurl, string field1, params string[] fields) instead.

15 SharePoint No-No's Heavy use of SPSite and SPWeb Always remembering to dispose of SharePoint objects Accidental changes of the Web Part signature

16 SharePoint 2013 API Types CSOM: Client-side object model. C#/VB only, use NuGet. JSOM: JavaScript object model. SP.ClientContext.get_current() for normal use. new SP.ClientContext('[url]') for specific SPSite. SSOM: Server-side object model. C#/VB only, use Microsoft.SharePoint assembly. Must be deployed on same farm. REST: REST web technologies and standard Open Data Protocol (OData) syntax. Either JavaScript or C#/VB helper package in NuGet.

17 Sharepoint 2013 Add-in Model An add-in is a self-contained functional application complete with user experience, data storage and business logic Add-ins give us the ability to delegate responsibility to different services or providers using a services based approach. With the new Add-in Model, SharePoint 2013 can be highly decoupled from extended functionality which may be hosted on entirely different infrastructure

18 Sharepoint 2013 Add-in Model Hosting Options SharePoint Hosted Provider Hosted Types of Add-ins Parts Immersive Full Page UI Custom Actions

19 SharePoint Hosted Add-Ins SharePoint hosted add-ins are entirely client-side code and run in the context of a dynamically generated SharePoint Web site.

20 Provider Hosted Add-In Provider-hosted add-ins run on a separate Web site and are surfaced in SharePoint through an iframe. Because they don't run on the SharePoint server they can use server side code.

21 Shapes - how your add-in will be interacted with Part IFrame hosted in a Web Part represented by the ClientWebPart class. The IFrame takes parameters which change the user experience of the add-in part.

22 Shapes - how your add-in will be interacted with Immersive Fully immersive experience by using the entire page. Includes a chrome control that provides your add-in with the current SharePoint cascading style sheet (CSS).

23 Shapes - how your add-in will be interacted with UI Custom Actions Custom actions that can direct to a page in your add-in, UI commands that extend ribbons and menus by adding the add-in to list items, documents, and more.

24 Add-in Model - High Trust Provider-hosted application for SharePoint on-premises In SharePoint 2013, the SPTrustedSecurityTokenIssuer provides access tokens for server-to-server authentication. "High-trust" is not the same as "full-trust" a high-trust application must still request application permissions. Trusted to use any user identity needed the application creates the user portion of the access token. Not intended to run in Office 365. Typically installed behind the firewall in instances that are specific to each individual company.

25 Add-in Model Low Trust Use a trust broker, such as Microsoft Azure Access Control Services, to act as token issuer between SharePoint & App Rely on the OAuth authorization code flow ("grant type") to delegate limited rights to apps to act as users. SharePoint relies on Microsoft Azure Active Directory. Can t interact with content outside the app web (without specifying permissions to host web.) Requested permissions are approved (or denied) by the installer of the app.

26 SSOM should still be used for Create a custom Windows PowerShell command Create a timer job Create an extension of Central Administration Create consistent branding across an entire SharePoint farm Create a custom Web Part, application page, or ASP.NET user control

27 Add-ins can be used for Features (Web-scoped only) Custom UI Actions (shortcut menu items and ribbon customizations) Remote event receivers Custom CSS/JavaScript files for use by SharePoint pages Modules (sets of files) List templates & List and library instances Custom list forms & Custom list views Custom content types Web templates (but not site definitions)

28 Enterprise Javascript Few SharePoint Developers have written an application entirely in Javascript Tooling can help Typescript Coffeescript Get to know JavaScript Modules, Promises, Namespaces, use strict Get to know JavaScript frameworks (jquery, KnockoutJS, AngularJS)

29 Enterprise Services Architecture How do we consume SharePoint data? How do we expose our Enterprise data to our new apps? Create a Service Oriented Architecture (SOA) Tooling includes ServiceStack, Web API 2, etc Not enough REST endpoints in legacy SharePoint? Create some!

30 Examples Web Parts Interaction via CSOM rather than SSOM REST Calls (depending on capability) iframes SP Page Other App

31 Examples Timer Jobs Host elsewhere Don t use web services if possible Use Specific least permissions Any platform you like Task Scheduler is perfect for this Windows Services not so much

32 CSOM/REST Trade Offs CSOM Seems Familiar to.net developers Well Documented in MSDN Currently gives more options in SharePoint Microsoft Only Technology CSOM Upload limit is 2 MB!!

33 CSOM/REST Trade Offs REST Upload limit is 2GB REST Documentation Limited in MSDN Wider Industry Support REST has larger request/response payloads Doesn t require referencing client assemblies Limits the footprint of your Web apps Windows 10 apps (HTML5 & JS) would need REST interface for any SharePoint operations

34 CSOM/REST Trade Offs

35 CSOM Capabilities in SP 2013 Sites, Webs, Features, Event Receivers, Site Collections Lists, List Items, Fields, Content Types, Views, Forms, IRM Files, Folders Users, Roles, Groups, User Profiles, Feeds Web Parts, Search, Taxonomy, WF, E-Discovery, Analytics, Business Data

36 REST Capabilities in SP 2013 Sites, Webs, Features, Event Receivers, Site Collections Lists, List Items, Fields, Content Types, Views, Forms, IRM Files, Folders Users, Roles, Groups, User Profiles, Feeds Search

37 Examples Application Pages Host elsewhere (decouple) Follow Single page Apps Methodology Consider browser version (HTML5/CSS3/JS support) Consider Bootstrap

38 Examples Event Receivers Emulate Remote Event Receivers Create Standard Class for dispatching event Perhaps Use a Message Queue Update the information remotely using.net CSOM

39 Skills Development MVC (ASP.NET MVC) MVVM/MVW (KnockoutJS, AngularJS,...) JavaScript/TypeScript jquery SPServices REST/CSOM

40 Conclusion Full trust solutions are still usable! Decoupled solutions are the future REST & CSOM parity with ASMX will come REST will win the race eventually Adopt good JavaScript practices Where possible make your applications consumers of SharePoint rather than extensions of SharePoint