Monday, April 27, 2015

Developing a SharePoint Hosted App

In this post we are going to talk about how can we Develop a SharePoint hosted Apps. This is divided in two primary steps.
  1. Develop the SharePoint Hosted App
  2. Discover the Deployed SharePoint Hosted App
Step - 1 : Develop the SharePoint Hosted App

Open visual studio 2013 , click on new Project , Select Apps for SharePoint 2013 template under Visual C# >Office/SharePoint>Apps.



Enter the project name as "DemoSPHApp" and provide the location where the code will reside.Click ok.Then it would It will open the wizard to create the project. Select the site ( Based on Developer / Team site definition) where you want to deploy the app . Select Hosting option as SharePoint-hosted.

























Click Finish. You would see primarily four main folders.
  1. Content - Responsible for App Content
  2. Images - Repository  for App Images
  3. Pages - All the app pages that needs to be deployed are stored in this location
  4. Script - All the scripts that is required for this app to function
Press  F5 and try to deploy the solution.you might run into the below error if you are trying to execute with the system account.

"Error occurred in deployment step "Installed app for SharePoint": The System Account cannot perform this action".

The Golden thumb rule is that ,You cannot deploy the apps with system account.Create another account, Provide the required permission on the SharePoint site and open the SQL server management studio and assign the db_owner permissions to this account, which you will be using to deploy the app for following databases.
  1. SharePoint_Config
  2. SharePoint_Admin_ [GUID]
  3. ContentDB to which the app is host. 
  4. Appmanagement_ServiceDB (app management service application database).
  5. SubscriptionSettings_ServiceDB (Subscription Settings service application database). 
Now use that account to deploy the apps using visual studio. I get the below error.



So now we Open the appmanifest file and Increment the app version by one. Now the App version is incremented from version 1.0.0.0 to 2.0.0.0. We also have modified the page title text on the "default.aspx" under the pages folder from "Page Title" to "Welcome to my First SharePoint Hosted App". Try to deploy the solution using the Visual Studio, one more time. Voola we see the new App.  


  
Step - 2 : Discover the Deployed SharePoint Hosted App

Click on Site content or you should be able to discover the newly deployed app on the left navigation (launch)  bar of the host Web.




Note : you can even publish the App using Visual Studio, Register the App on the App Catalog and make it Discoverable.









No comments: