Thursday, July 11, 2013

SharePoint 2013 - App Development


Pre-Requisite: Have your virtual machine ready with Microsoft SharePoint 2013 and Visual Studio 2012 installed on it.
This article is divided into following three sections:
  1. Setup App Catalog
  2. Develop a SharePoint-Hosted App
  3. Deploy the App

Setup App Catalog:

For App development in SharePoint 2013, first we need to setup an App Catalog. What is an App Catalog? App Catalog is a special Site Collection where all the apps are published and stored. App Catalog site collection is setup per web application. So once an app is hosted in an app catalog, it is available to all the site collections within that web application.
Below are the steps to create and setup an App Catalog to deploy a SharePoint-Hosted App:
  1. Go to the Central Administration and select Apps from the left menu
    2013-04-22-SharePoint2013AppDev-01.PNG
  2. From the App Management section, select Manage App Catalog
    2013-04-22-SharePoint2013AppDev-02.png
  3. On the Manage App Catalog page, select Create a new app catalog site and hit OK.
    2013-04-22-SharePoint2013AppDev-03.png
  4. On the Create App Catalog page, provide the required fields along with the Farm account and hit OK.
    2013-04-22-SharePoint2013AppDev-04.png
  5. Once done, you should see following screen.
    2013-04-22-SharePoint2013AppDev-05.png
  6. Browse to the App Catalog site and it should look like this:
    2013-04-22-SharePoint2013AppDev-06a.png
  7. Apps are designed to run from a separate Domain name. To configure that we need an entry in the Domain Name Server (DNS). I have created a new domain apps.com. * in the domain is used so that we can use the app name there.
    2013-04-22-SharePoint2013AppDev-07a.png
  8. You should be able to ping the domain name after its configured.
    2013-04-22-SharePoint2013AppDev-08a.png
  9. Run the following script to create a new service application running in its own pool
    2013-04-22-SharePoint2013AppDev-09a.png
    Script:

    01add-pssnapin "Microsoft.Sharepoint.Powershell"
    02 
    03$account = Get-SPManagedAccount Domain\go-SvcSpSetupDev
    04 
    05Remove-SPServiceApplicationPool -Identity SettingsServiceAppPool
    06 
    07$appPoolSubSvc = New-SPServiceApplicationPool -Name SettingsServiceAppPool -Account $account
    08 
    09$appSubSvc = New-SPSubscriptionSettingsServiceApplication -ApplicationPool $appPoolSubSvc -Name SettingsServiceApp -DatabaseName SettingsServiceDB
    10 
    11$proxySubSvc = New-SPSubscriptionSettingsServiceApplicationProxy -ServiceApplication$appSubSvc

    Verify:
    Go to Central Administration -> Application Management -> Service Applications -> Manage Service Applications
    2013-04-22-SharePoint2013AppDev-10a.png
    You should be able to see SettingsServiceApp
    2013-04-22-SharePoint2013AppDev-11a.png
  10. Now, let's configure App URL.
    2013-04-22-SharePoint2013AppDev-12a.png
    Enter the domain and prefix
    2013-04-22-SharePoint2013AppDev-13a.png

Develop a SharePoint-Hosted App

  1. Launch Visual Studio 2012 and create an App for SharePoint 2013.
  2. Give the app name, site name and select SharePoint-hosted
    2013-04-22-SharePoint2013AppDev-14a.png
  3. Write your Client Object Model (CSOM) code in App.js.
  4. Select Build -> Publish and then Finish. You will get an App1.app ready to deploy.

Deploy the App

  1. Go to the App Catalog site and select Apps for SharePoint library.
  2. Upload App1.app here by selecting new app link.
    2013-04-22-SharePoint2013AppDev-15a.png
  3. Go to the home page and select Settings icon -> Add an app
    2013-04-22-SharePoint2013AppDev-16b.png
  4. Look for App1 and select it and then click Trust It. < style="text-align: center">2013-04-22-SharePoint2013AppDev-17b.png

  5. The App1 will take some time to get installed and will be visible in Site Content.
    2013-04-22-SharePoint2013AppDev-18b.png
    2013-04-22-SharePoint2013AppDev-19b.png
  6. Click the app to run it.
    2013-04-22-SharePoint2013AppDev-21.PNG
  7. If you observe the URL of the app. It looks something like this:

    http://[app prefix]-[app hash].[app domain]/[relative site URL]/[app name]/Pages/Default.aspx
    e.g.
    http://app-441ae93071a873.apps.com/sites/AppCat/App1/Pages/Default.aspx
  8. 2013-04-22-SharePoint2013AppDev-20.png
Ref 1: http://technet.microsoft.com/en-us/library/fp161234.aspx 
Ref 2: http://msdn.microsoft.com/en-us/library/jj164070.aspx

1 comment:

  1. Hi Friends its my post for my Blog...please give your comments...

    ReplyDelete