App Development in SharePoint 2013 Cincinnati SharePoint User Group 04/24/2014
About McGladrey Ranked fifth-largest assurance, tax, and business consulting provider in the U.S., for RSM McGladrey, Inc. and McGladrey & Pullen, LLP combined (Source: Accounting Today 2010 Top 100 Firms) - Nearly 90 offices in the U.S. - 7,000 employees in the U.S. Members of RSM International, one of largest global networks of independent accounting, tax, and consulting firms - Presence in 76 countries - More than 32,000 people in 736 offices Provides global resources with a single point of contact Delivering outstanding client service for over 80 years McGladrey is the brand under which RSM McGladrey, Inc. and McGladrey & Pullen, LLP serve clients business needs. The two firms operate as separate legal entities in an alternative practice structure. 1
Technology Consulting Capabilities We offer a comprehensive scope of technology services, covering IT Strategy, Application and Systems Integration, Infrastructure and Outsourcing. Advise Deliver Maintain Business Performance Improvement Consulting Applications Infrastructure Support Strategy and Advisory Design and Implementation Design and Implementation Business & Technology Outsourcing Strategy Development Assessments Due Diligence System Selection Business Continuity and Disaster Recovery Benchmarking/Best Practices Project and Program Management Enterprise Resource Planning (ERP) Customer Relationship Management (CRM) Business Analytics Corporate Performance Management Systems Integration Knowledge Management, Portals and Collaboration Network Design and Implementation (LAN/WAN) Carrier Assessment/TEM Server Virtualization Storage and Recovery Desktop/Application Delivery Unified Communications and Mobile Computing Finance and Accounting Outsourcing IT Outsourcing CIO Advisory Application Outsourcing Infrastructure Outsourcing Hosting/Private Cloud Managed Services Cloud Solutions Software as a Service (SaaS), Platform as a Service (PaaS), Infrastructure as a Service (IaaS) Enterprise Risk Management 2 2
Introduction Arun Aggarwal - Consulting Manager - SharePoint Practice - Great Lakes Region - Dayton, OH arun.aggarwal@mcgladrey.com
Developing SharePoint apps Introduction to SharePoint apps Developing SharePoint apps Distribution and deployment App lifecycle events
Pain points with SharePoint solutions Custom code runs inside SharePoint environment Custom code has dependencies on DLLs Permissions model based on entirely on user identity - No permissions for the solution itself - Impersonation helps with too-little-permissions problem - Impersonation causes too-many-permissions problem SharePoint solutions are hard to manage
SharePoint 2013 Deployment Options On-premises SharePoint Online
SharePoint app life cycle
A big picture SharePoint 2013 SharePoint Farm Site Collection 1 List 1 List Item 2 Site Collection 2 November 13 M T W T F S S 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 Laptop Doc Lib Workstation SharePoint App (Hosted) Smart Phone Tablet Remote Application (LAMP, ASP.NET, ASP.NET MVC, Java.) Custom Application 1 Custom Application 2 SharePoint App (Hosted) Kiosk (PHP.NET)
SharePoint app model overview SharePoint app model based on the following assumptions - Apps supported in Office 365 and in on-premises farms - App code never runs in SharePoint host environment - Apps talk to SharePoint using Web service only - App code is authenticated and has established identity - App has permissions independent of user permissions - Apps deployed to catalogs using a publishing scheme - Published apps are easier to find, install and upgrade
Important Terms Hosting Model - SharePoint-hosted - Cloud-hosted App Web Remote Web App Catalog App Store (SharePoint Store) App Domain Tenancy
App Development - On-premises 2 Service Applications required App Management Service Application (Central Administration) Microsoft SharePoint Foundation Subscription Settings Service Application (PowerShell script is the only way) App Domain PowerShell Script Tenant Name PowerShell Script
Error resolution tips Error resolution in the SharePoint 2013 app development environment - Disable the loopback check - No UI to create Microsoft SharePoint Foundation Subscription Settings Service Application PowerShell script available to jump start
PowerShell helper scripts # ----------------------------------------------- # Load SharePoint PowerShell snapin Write-Host Write-Host "(2 of 6) Verify SharePoint PowerShell Snapin Loaded" -ForegroundColor White $snapin = Get-PSSnapin Where-Object {$_.Name -eq 'Microsoft.SharePoint.PowerShell'} if ($snapin -eq $null) { Write-Host ".. loading SharePoint PowerShell Snapin..." -ForegroundColor Gray Add-PSSnapin "Microsoft.SharePoint.PowerShell" } Write-Host " Microsoft SharePoint PowerShell snapin loaded" -ForegroundColor Gray # assign root domain name to configure URL used to access app webs Set-SPAppDomain "apps.devsharepoint11" confirm:$false $account = Get-SPManagedAccount NATIONALDEV\spadmin Remove-SPServiceApplicationPool -Identity "SettingsServiceAppPool" $apppoolsubsvc = New-SPServiceApplicationPool -Name SettingsServiceAppPool -Account $account Remove-SPServiceApplicationPool -Identity "AppServiceAppPool" $apppoolappsvc = New-SPServiceApplicationPool -Name AppServiceAppPool -Account $account $appsubsvc = New-SPSubscriptionSettingsServiceApplication ApplicationPool $apppoolsubsvc Name SettingsServiceApp DatabaseName SettingsServiceDB $proxysubsvc = New-SPSubscriptionSettingsServiceApplicationProxy ServiceApplication $appsubsvc $appappsvc = New-SPAppManagementServiceApplication -ApplicationPool $apppoolappsvc -Name AppServiceApp - DatabaseName AppServiceDB $proxyappsvc = New-SPAppManagementServiceApplicationProxy -ServiceApplication $appappsvc # assign name to default tenant to configure URL used to access web apps Set-SPAppSiteSubscriptionName -Name "McGladreyTenant" -Confirm:$false
Disable the loopback check Click Start, click Run, type regedit, and then click OK In Registry Editor, locate and then click the following registry key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSe t\control\lsa Right-click Lsa, point to New, and then click DWORD Value Type DisableLoopbackCheck, and then press ENTER Right-click DisableLoopbackCheck, and then click Modify In the Value data box, type 1, and then click OK Quit Registry Editor, and then restart your computer
App Url (Start Page) App UID Tenant App Domain App Name http://mcgladreytenant- 2cfd74a2325d8b.apps.devsharepoint11/Share PointAppRestDemo/Pages/Default.aspx
Types of app No Hosting Type of Code Technology Comments (Server / Client) (CSOM / REST) 1 SharePoint Hosted Server Code CSOM Not Allowed 2 SharePoint Hosted Server Code REST Not Allowed 3 SharePoint Hosted Client Code CSOM Possible 4 SharePoint Hosted Client Code REST Natural for JavaScript 5 Cloud Hosted Server Code CSOM Natural for C# 6 Cloud Hosted Server Code REST Possible 7 Cloud Hosted Client Code CSOM Possible (Not desirable) 8 Cloud Hosted Client Code REST Possible (Not desirable)
Client-side JavaScript with CSOM $(document).ready(function () { SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function () { sharepointready(); }); });
Client-side JavaScript with REST OData Open Data protocol Uses standard HTTP verbs to send and retrieve data in standardized formats such as Atom, JSON, plain XML Requires parsing together these URLS according to the rules outlined by OData protocol http://devsharepoint11/ _api/web/?$select=title service root - http://devsharepoint11 resource path - _api/web query options -?$select=title
Server-side with CSOM protected void Page_Load(object sender, EventArgs e) { // retrieve app web URL from incoming query string parameter string appweburl = Page.Request["SPAppWebUrl"]; using (ClientContext clientcontext = new ClientContext(appWebUrl)) { Web appweb = clientcontext.web; clientcontext.load(appweb); clientcontext.executequery(); lblappwebtitle.text = appweb.title; }
Server-side with CSOM - 2 // code added to start page protected void Page_Load(object sender, EventArgs e) { // cache url to web app for other pages Cache["SPAppWebUrl"] = Page.Request["SPAppWebUrl"]; } generic handler named appwebtitle.ashx $("#appwebtitle").load("/pages/appwebtitle.ashx");
Server-side with REST // retrieve URL to app web string appweburl = Page.Request["SPAppWebUrl"]; // create URL for REST call to query for app web Title property Uri uri = new Uri(appWebUrl + "/_api/web/?$select=title"); // transmit HTTP GET request to SharePoint host environment HttpWebRequest requestget = (HttpWebRequest)WebRequest.Create(uri); requestget.credentials = CredentialCache.DefaultCredentials; requestget.method = "GET"; HttpWebResponse responseget = (HttpWebResponse)requestGet.GetResponse(); // retrieve Title property from XML returned by SharePoint host environment XDocument doc = XDocument.Load(responseGet.GetResponseStream()); XNamespace ns_dataservices = "http://schemas.microsoft.com/ado/2007/08/dataservices"; lblappwebtitle.text = doc.descendants(ns_dataservices + "Title").First().Value; HttpWebRequest GetResponse Method HttpWebRequest and HttpWebResponse and XDocument class converts XML document to create HTML list element
Server-side with REST 2 Form Digest In client side the value of form digest is available on the page. Not in server side. There is a get call required to get the value private string GetFormDigest(){ string appweburl = Cache["SPAppWebUrl"].ToString(); Uri uri = new Uri(appWebUrl + "/_api/contextinfo"); HttpWebRequest requestpost = (HttpWebRequest)WebRequest.Create(uri); requestpost.credentials = CredentialCache.DefaultCredentials; requestpost.method = "POST"; requestpost.contentlength = 0; HttpWebResponse responsepost = (HttpWebResponse)requestPost.GetResponse(); XDocument doc = XDocument.Load(responsePost.GetResponseStream()); XNamespace ns_dataservices = "http://schemas.microsoft.com/ado/2007/08/dataservices"; return doc.descendants(ns_dataservices + "FormDigestValue").First().Value; }
Demo
SharePoint tenancies A tenancy is a set of site collections - Configured and administered as a unit - Created with administrative site collection - A scope for provisioning new site collection - Central concept to site management in Office 365 - A requirement for installing SharePoint apps What about tenancies in on-premise farms? - Most farms do not have explicitly created tenancies - To add support for SharePoint apps, on-premise farm can be configured with a farm-wide default tenancy
Service application support for apps App support requires two service applications - App Management Service - Site Subscription Management Service - These two services must be created in onpremises farms to support apps
App installation scopes Site-Scoped Installation - App is installed in a specific site - App is launched from same site - This site is known as host web Tenancy-Scoped Installation - App installed -> app catalog site - App available many host webs - Host webs access one app instance - Centralizes app management
SharePoint app architecture SharePoint-hosted apps - App resources added to SharePoint host - Stored in child site knows as app web - App can have client-side code - App cannot have server-side code Cloud-hosted apps - App resources deployed on remote server - Remote site known as remote web - App can have client-side code - App can have server-side code
App start page Every app requires a start page - Start page provides entry point into app - SharePoint adds app launcher to Site Contents in host web - SharePoint-hosted app start page hosted by SharePoint - Cloud-hosted app start page hosted in remote web
App hosting models SharePoint-hosted App - App deployed to app web created under child site Provider-hosted App - App deployed to remote web on remote web server - Developer deploys remote web prior to app installation Auto-hosted App - App deployed to remote web in Office 365 environment - Office 365 deploys remote web during app installation
App manifest All apps require app manifest (AppManifest.xml) - SharePoint reads manifest metadata during app install - Metadata used to configure installed app instances - Visual Studio 2012 provides app manifest designer
Start Page URL Dynamic tokens used in start page URL - SharePoint-hosted apps use ~appweburl token ~appweburl/pages/default.aspx - Cloud-hosted apps use ~remoteappurl token ~remoteappurl/pages/default.aspx - All apps should use (StandardTokens) token ~appweburl/pages/default.aspx ~remoteappurl/pages/default.aspx
App Web App Web is created during app installation - App Web created as child to site where app is installed SharePoint-hosted apps must create app web - App must add start page and related resources - App can add other SharePoint elements (i.e. lists) Cloud-hosted apps can optionally create app web - Most cloud-hosted apps will not create an app web - Cloud-hosted app can create app web if needed
App Web hosting domain App web pages served out of isolated domain - Isolates JavaScript code on app web pages - Allows SharePoint to authenticate callbacks from app https://mcgladreytenantee060af276f95a.apps.mcgladrey.com/helloworld App URL to app web made up of 4 parts - Tenancy name: McGladreyTenant - APPUID: ee060af276f95a - App web hosting domain: apps.mcgladrey.com - App name: HelloWorldApp
Host web features SharePoint apps can extend UI three ways - Start Page (required) - App Parts - UI custom actions App Parts and UI custom actions added host web - Added to host web using a host web feature - Users add app parts just like adding web parts - UI custom actions used to extent ribbon and ECB menu - The development details available later
App distribution overview App Packaging - Packaging app resources for distribution App Publication - Making app available for installation and upgrade App Installation - Make app available for use App Upgrade - Replace current version of app with newer version
App package SharePoint apps distributed using app packages - App package is ZIP archive file with.app extension - Built according to Open Package Convention (OPC) - Same packaging format used in Apps for Office - App package must contain Appmanifest.xml - App package will often contain file for app icon - MySharePointApp.app AppManifest.xml AppIcon.png.config.xml AppIcon.png
App Web Solution Package App package contains inner WSP for app web - Elements deployed to app web using solution package - Solution package built into app package as inner WSP - All SharePoint-hosted apps will have an inner WSP in their app package - Cloud-hosted apps will not have an inner WSP in their app package unless the have been implemented to create an app web
Packaging host web features Host web feature elements added at top level - Element.xml file added for each app part - Element.xml file added for each UI custom action - Feature.xml file added for host web feature - Visual Studio adds GUI to file names
Packaging for autohosted apps Autohosted apps packaged with extra resources - Office 365 requires resources to deploy remote web Built into app package as web deploy package (web.zip) - Office 365 requires resources to create SQL Azure DB Built into app package as Data Tier Application Package (dacpac)
Publishing apps App distributed based on publishing scheme - Publishing involved uploading app package to catalog - Provides better app discovery, installation and upgrade Office Store is catalog available to general public - Developers publish apps to Office Store - Anyone can discover apps and purchase / install them App catalog site for publishing at private scope - Implemented as a SharePoint site collection - Used in Office 365 tenancies and in on-premise farms - Must be explicitly created in on-premised farm
Creating an app catalog site App catalog site created in Central Administration - App catalog site is created at web application scope
Apps for SharePoint document library App catalog site contains support for - Publishing SharePoint apps - Publishing Apps for Office - Managing user request for apps Apps for SharePoint is special document library - It is the place where you publish SharePoint apps - You upload app package and add related metadata
Installing apps You must be administrator of site to install an app - Click add an app link on Site Contents page - This takes you to app discovery page - Click an app tile to install it - After installation, app tile added to Site Contents page - App tile provides fly-out menu to assist with app management
Installing apps at tenancy scope App catalog site used for tenancy-scoped install - Step 1: Publish app to app catalog site - Step 2: Install app in same app catalog site - Step3: Configure app to make it available in other sites.
Upgrading apps Overview of SharePoint app upgrade process - App catalog tracks current version number of app - SharePoint host records app version at install time - Updated version of app can be uploaded to app catalog - SharePoint host notifies used when there s new version User makes choice whether upgrade or not - User is never forced to upgrade - If user decides to upgrade, it involved clicking a button - Provider-hosted apps must support multiple versions
App lifecycle events SharePoint app models support app events - App events for installation, upgrade and uninstall - SharePoint host calls to entry point in remote web - Not support in SharePoint-hosted apps - Added to app project using property sheet
Programming App Events App Events implemented using ProcessEvent method
Questions