What is App Model – SharePoint 2013

Introduction

In this post we will discuss about the concept of SharePoint Apps, which is the most newly added aspect in SharePoint 2013. The app programming model helps to create rich apps and publish them in an Office Store or public market place. The app model focuses on the development by customizing and extending the SharePoint sites without full trust access to the target farm.

Why Apps Model?
1) First of all there is no dependency for custom code on SharePoint Server since it executes on Client-Browser or may be in some other scope like IIS or Windows Azure.
2) Apps communicate with SharePoint using Client side object model (CSOM) or Rest Services with OAuth being the authentication mode.
3) Remarkable usability in Tablets and Mobile devices.
4) One step ahead for development in future where cloud hosting could be more preferrable.
5) Moreover, in SharePoint 2013 everything is an app including Lists, Libraries etc.
6) SharePoint apps can be developed with any programming language or technology, provided they are hosted outside the SharePoint (autohosted or provider-hosted model).
7) SharePoint apps can be created using PHP, Java, or any other technology capable of communicating with SharePoint via the new REST API and the OAuth protocol.

Types of Configuration 
1) Full-Page: These apps have an independent UI irrespective of the Sites on which they are hosted. A “Back” button should be provided to navigate back to the parent site which triggered the app.
2) App Parts: App parts renders inside an IFrame from whithin the pages of the parent site. They are also known as Client Parts.
3) UI command extension: These apps are used to extend the UI of the parent site. For example, you can create an app to add a new button to the ribbon.

Types of Hosting
1) SharePoint-hosted: These apps are hosted on the SharePoint Farm within a subweb of the parent site and are capable of using the various SharePoint artifacts such as lists, fields, content types, webparts etc.
2) Auto-hosted: These apps are hosted on Microsoft Windows Azure.They can communicate with SharePoint through events or Client Object Model. “OAuth” is used to enforce secure communication.
3) Provider-hosted: These are very much similar to the Auto-hosted apps, the only difference being that they are deployed on an external hosting enviornment other than SharePoint enviornment and does not necessarily use the Windows Azure environment.

Security Perspective
From a security point of view one can trust SharePoint 2013 app model to be thouroughly secured.
A definite set of permissions are requested by the SharePoint App when it is installed. The app will be installed only if the current user can grant the requested permissions, otherwise the app will not install. Pretty straight formward. Isn’t it!!

App Development environment
1) “Napa” office 365 dev tools: This tool is purely client side and ideal for creating SP hosted apps. It doesn’t support code behind you can view only markup. Developers can also create apps for Office in a web-based environment hosted in Office 365. Previously code-named “Napa,” this subscription-based online experience is being updating on a weekly basis, according to Microsoft. It consists of a SharePoint site in Office 365 configured for apps and the “Napa” Office 365 Development Tools. You can sign up for the Office 365 Developer Site on the Microsoft web site. The subscription costs $99 per year. But Visual Studio Ultimate and Visual Studio Premium with MSDN subscribers receive a one-year Office 365 Developer Subscription as a benefit, and Office 365 Plan E1 or E3 customers can provision a Developer Site as part of their subscription. A 30-day trial is available.

2) Visual Studio: For developing apps using Microsoft .NET and Microsoft Visual Studio 2012, you will need the Office Developer Tools for Visual Studio 2012, which can be downloaded and installed through the Web Platform Installer 4.0 tool.

You also will need to install the following tools and libraries:
i) SharePoint client components
ii) Windows Identity Foundation SDK
iii) Workflow Tools SDK and Workflow Client SDK
iv) Windows Identity Foundation SDK and Windows Identity Foundation extensions

Note:- If you are working on a server with SharePoint 2013 installed, you need to add only Visual Studio 2012 and the Office Developer Tools for Visual Studio 2012. All the other libraries and tools are already part of the installation set of any SharePoint 2013 environment.

App Deployment
There are three ways that you can access CSOM functionality, so the deployment model that you are using for your SharePoint 2013 app will determine the option that you choose.
1) .NET / Silverlight API
2) JavaScript API
3) REST API

Creating a SharePoint 2013 SharePointHosted App

In this post we will create a SharePoint-hosted and also discuss about the important artifacts inside it.

Pre-requisite
1) Before even thinking of creating an app, you must configure the environment for deploying the app. Otherwise, you will get the following  error while deploying:-
“Error occurred in deployment step ‘Install app for SharePoint’: Failed to install app for SharePoint. Please see the output window for details.”
This happens because apps are disabled on the site. You can follow the detailed steps to configure apps environment here.
(https://www.nothingbutsharepoint.com/sites/devwiki/articles/Pages/SharePoint-2013-App-Development.aspx)
2) Check whether Microsoft Office Developer Tools for Visual Studio 2012 are installed. Otherwise app project templates wont be visible in Visual Studio 2012. You can download it here.

Following are the main steps:
We shall analyze the following steps to get a better understanding about SharePoint hosted apps:-
1) Creating a SharePoint-Hosted App Project
2) Understanding the App Project folder structure
3) Deploying the App to the App website
4) Customizing the App

So let’s get started….!!!!

Creating a SharePoint-Hosted App Project

First of all, create a new project in visual studio 2012 selecting Apps for SharePoint 2013 located in Office/SharePoint->Apps as show in the following image.

Enter a suitable title, specify the Site collection where the app should be deployed and select SharePoint hosted. Click Finish to continue.


Understanding the App Project folder structure
Now that the project has been created, first of all, let’s discuss about the components present inside an app at the time of creation.

Feature: The provisioning of all the contents inside the app website is done by the web scoped feature inside this folder.

Package: This folder contains the package for the deployment of app on the target site.

Content: Custom CSS styles related to the app are deployed from this folder.

Images: All the images related to the app  are deployed from this folder. Includes AppIcon.png file, which is the default icon of your app.

Pages: Consists of a Module feature which deploys all the pages of the target app website. The project template creates a Default.aspx page by default.

Scripts: Includes JavaScript files for deploying jQuery scripts, some JavaScript references, and the App.js file, which is the JavaScript Client Object Model entry point of the app.

AppManifest.xml : All the configuration and deployment information related to the app is included in this file.

packages.config : This file consists of the information about the packages referenced by the Visual Studio project such as jQuery packages and so on.


Deploying the App to the App website

Without making an changes, straightaway deploy the solution.

Open the output window and you will see the status of the deployment.

Once the app is successfully deployed you can see that the app is listed in the Site Contents page.

Click on the app and you will be prompted whether you trust this app. Click Trust It button.

Note: You might run into a scenario where you are prompted for credentials and you won’t be able to log in to the app page even after providing your credentials multiple times. You can find the work around here.

You will be redirected to the app page (Default.aspx page that you saw in the Pages folder in the project).

Customizing the App
Open the Default.aspx page in our project  and modify the PlaceHolderMain contents as follows. Well, that’s nothing much. Just another div  tag named “appDiv” and a button with a function named ‘btnClick()‘ for displaying some custom text.

Code Snippet
  1. <asp:Content ContentPlaceHolderID=”PlaceHolderMain” runat=”server”>
  2.     <div>
  3.         <p id=”message”>
  4.             <!– The following content will be replaced with the user name when you run the app – see App.js –>
  5.             initializing…
  6.         </p>
  7.     </div>
  8.             <div id=”appDiv”>
  9.     </div>
  10.     <button onclick=”btnClick();”>Click Me!</button>
  11. </asp:Content>

Now go to the app.js file inside the Scripts folder inside our project and add a new function named ‘btnClick‘ as follows:

Code Snippet
  1. function btnClick() {
  2.     $get(‘appDiv’).innerHTML = “<p>This is my first SharePoint 2013 App!</p><p>This is a SharePoint Hosted App!</p>”;
  3.     return false;
  4. }

Deploy the app again and go to the app page. You will see that our new functionality has been added to display custom text when the button is clicked.

Remember this is just a sample app to demonstrate the steps for creation. The actual capabilities of apps are seamless.

Creating a SharePoint 2013 Autohosted App

In this post we will discuss about the Autohosted apps for SharePoint 2013.

Overview
The Autohosted app model are created on sites which are already provisioned on Windows Azure websites.
Unlike SharePoint hosted apps, an app web is not present in autohosted apps for storing data. It uses its own SQL Azure based infrastructure instead and works only for SharePoint Sites hosted on Office 365 or SharePoint Online.

Steps for creating an Autohosted App
Now lets create an auto-hosted app for a SharePoint 2013 Team site created on Office 365.

1) Open Visual Studio 2012 and select Apps->App for SharePoint 2013.

2) Enter the URL of the SharePoint site which is hosted on Office 365 developer site. If you don’t have an Office 365 developer account, you can easily signup for a 30 day trial account. You can see the detailed steps here.

3) Once you have created the Office 365 developer site account, enter the URL of the SharePoint Site where you wish to deploy the app and select Autohosted option.

4) You will notice that there are 2 projects (one for app and the other for web) created under the solution. Go to the Default.aspxand enter some sample text.

5) Right click on the app project and select publish.

6) The following window will pop up. Click on Finish button to publish the app.

7) Once the app is published, the folder containing the .app file will open.

8) Now open the SharePoint site where you wish to deploy the app and click on the “new app to deploy” link.

9) The following popup will appear. Click on the upload link.

10) Enter the .app file location for uploading the app to the site.

11) Once the app is successfully installed, click on Deploy button to deploy the app.

12) The app will seek for permission to deploy. Click on Trust It button to give permission.

13) Once the app is successfully deployed, you can see it in the Site Contents page.

14) Click on the app and you will be navigated to the app page.

Creating a SharePoint 2013 Provider Hosted App

In this post we will go through the steps required to create a provider-hosted app.

Overview
Provider hosted apps are Cloud-hosted apps that use a third-party provider for hosting the web application rather than Windows Azure websites. The third-party provider can manually provision Windows Azure or can be based on anything else, even an on-premises server farm of your own. In provider hosted apps the browser request is sent to the SharePoint server which in turn calls the .Net Application as a Separate Application.

Steps for creating a Provider-Hosted App
Now lets create a Provider-hosted app for a SharePoint 2013 Team site created on Office 365.

1) Open Visual Studio 2012 and select Apps->App for SharePoint 2013.

2) Enter the URL of the Site collection where you wish to deploy the app and select Provider Hosted option. Click Next button.

3) On the second page, the Visual Studio wizard for creating a provider-hosted app asks you to choose between using Windows Azure Access Control Services (ACS) for authentication and authorization, rather than using a high-trust configuration based on a private certificate and asymmetric keys exchange.

The first choice is suitable when your app will be used on sites hosted on Office 365.
The second choice, High Trust, is suitable for on-premises scenarios.

4) You will notice that there are 2 projects (one for app and the other for web) created under the solution. Go to the Default.aspx and enter some sample text.

5) Right click on the app project and select publish.

6) The following window will pop up. Select New option and provide a name for the Profile. Click OK and then Next button.

In the next page you will be asked to provide the url where the site is hosted, a Client ID and a Client Secret.
Client ID is nothing but a guid but you can’t create it from visual studio. For creating the Client ID go to the AppRegNew.aspx page. The page will present inside the layouts folder. The URL would be something like https://MyServer/sites/MySiteCollection/_layouts/15/Appregnew.aspx.

Go back to visual studio and copy the Client ID.

You will reach the final page of the wizard. Click Finish.

7) Once the app is published, the folder containing the .app file will open.

8) Now open the SharePoint site where you wish to deploy the app and click on the “new app to deploy” link.

9) The following popup will appear. Click on the upload link.

10) Enter the .app file location for uploading the app to the site.

11) Once the app is successfully installed, click on Deploy button to deploy the app.

12) The app will seek for permission to deploy. Click on Trust It button to give permission.

13) Once the app is successfully deployed, you can see it in the Site Contents page.

14) Click on the app and you will be navigated to the app page.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s