Thursday 21 January 2016

App development in SharePoint

In this post you will get basic understanding of app development in SharePoint 2013 using visual studio 2012.

Apps main purpose in SharePoint 2013 is to provide the specific functionality or information to a SharePoint site. While trying to develop your first App you might get lots of errors initially, so I am here to resolve those. The main aim of this post is to cover all possible errors and resolutions for those errors you might get during the development.

Once you develop these apps where you will store?. Before starting the app development you have to check what are the hosting models available in SharePoint 2013.

Below are Microsoft SharePoint hosting options available.

    Hosted in a SharePoint environment
    Provider-hosted
    Hosted in the cloud (Windows Azure autohosted)

In this article we will use SharePoint-hosted option to develop our first app.
Prerequisites:

Make sure your environment is up and running before starting the development of apps.

Set-up your development environment using below link:

http://msdn.microsoft.com/en-us/library/fp179923(office.15).aspx

Please check this article  for configure the apps .

Make sure you don't miss even single step in the above articles, otherwise you will get issues during app development.

Have you completed setup the environment and app configuration?

If you have completed the setting up the development environment and apps configuration, then you are ready to go........
Developing an App:

Open visual studio 2012, click on new project select Apps under office/SharePoint from which select project type as Apps for SharePoint 2013.

Enter your project name  here it is MyFirstApp.
App for SharePoint 2013

Click ok. It will open the wizard to create the project.

Select the site where you want to deploy the app. "http://sharepoint-journey.com/sites/appdevelopment".

Hosting option should be : SharePoint-hosted.
App for SharePoint 2013

Click Finish. It will create the project.

Right click on the project and deploy it. You will get below error with SharePoint server RTM.


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


The System Account cannot perform this action

Note: You cannot deploy the apps with system account in RTM to provide the security.


So what to do?

Use another account to deploy the apps using visual studio 2012 from your development machine.

To do that login with the new account into the machine. Open the Project which you have created with system account before i.e. MyFirstApp.

Try to deploy it?.

You will get below error.

"Error occurred in deployment step "Installed app for SharePoint": The local SharePoint server is not available. Check that the server is running and connected to the SharePoint Farm"
The local SharePoint server is not available

To resolve the above error switch back to system account and open the SQL server management studio and assign the db_owner permissions to an account which you are using to deploy the app for below databases.

    SharePoint_Config.
    SharePoint_Admin_ [GUID].
    Your current web application that needs to host the app.
    Appmanagement_Service_DB (app management service application database).
    SubscriptionSettings_Service_DB (Subscription Settings service application database).

Provide full control permissions to the site collection where we are deploying the app.

Please check here to find a new way of assigning the permissions in SharePoint 2013.

Make sure that you have added that user under Farm administrators account from central administration.
db_owner permissions

You have all the required the permissions now, to cross verify try to browse the site "http://sharepoint-journey.com/sites/appdevelopment" where you want to deploy the app, if you are able to open the site, then  you are ready to deploy the app.
Errors while deploping the apps:

Sometimes you may get errors like below in app development.

"Error occurred in deployment step "Installed app for SharePoint": App management Shared Service proxy is not installed".
App management Shared Service proxy is not installed

To resolve the above error, you need to use step2 in app configuration article.

"Error occurred in deployment step "Installed app for SharePoint": Failed to install app for SharePoint. Please see the out put window for details"
Failed to install app for SharePoint. Please see the out put window for details

To resolve the above error you need to configure the app catalog URLs from the central administration.

The above errors are occurring because you didn't follow the configuration guide to configure the apps. Please follow without missing any step, then you should not be getting any error.
Update July 2013:

Today when I try to deploy an App I got below error.

@"Error 1

        CorrelationId: 37a5cc7a-891b-45e6-8601-25f4d0134e86

        ErrorDetail: The content database on the server is temporarily unavailable.

        ErrorType: Transient

        ErrorTypeName: Intermittent

        ExceptionMessage: Microsoft.SharePoint.SPException: Settings or services required to complete this request are not currently available.  Try this operation again later.  If the problem persists, contact your administrator.

   at Microsoft.SharePoint.SPSubscriptionSettingsServiceApplicationProxy.ProcessCommonExceptions(Exception ex, SPServiceLoadBalancerContext context)

   at Microsoft.SharePoint.SPSubscriptionSettingsServiceApplicationProxy.ExecuteOnChannel(CodeBlock codeBlock)

   at Microsoft.SharePoint.SPSubscriptionSettingsServiceApplicationProxy.GetSubscriptionMetadata(Guid subscriptionId)

   at Microsoft.SharePoint.SPSiteSubscriptionSettings.EnsureSubscriptionMetadata()

   at Microsoft.SharePoint.Utilities.SPUtility.IsValidAppInstallationConfiguration(SPSite site)

   at Microsoft.SharePoint.Utilities.SPUtility.CanInstallAppsInSite(SPSite site)

   at Microsoft.SharePoint.Packaging.SPUserCodeSolutionDeploymentGroup.Deploy()

   at Microsoft.SharePoint.Administration.SPAppTask.DeployOperation()

   at Microsoft.SharePoint.Lifecycle.MonitoredTaskExecution.DoTask()

        Source: AppWeb

        SourceName: App Web Deployment

Error occurred in deployment step 'Install app for SharePoint': Failed to install app for SharePoint. Please see the output window for details.
Solution:

We have already configured two essential service applications in our environment those are

    App Management Service Application.
    Microsoft SharePoint Foundation Subscription Settings Service Application.

To resolve the error, we need to configure one more service application. That is ..

     3. Managed Metadata Service Application.

Once you deploy the app, it will show the below details in output window that App was installed at so and so location.
Deploy the app
Verification of app Deployment:

Congratulations you have developed your first app in SharePoint 2013 using visual studio 2012.

We will try to open the site and find out how it looks. Open the site from where you have deployed the app.

In this demo it is "http://sharepoint-journey.com/sites/appdevelopment".
Host Web

Under the Recent section on left navigation you can observe the app which you have deployed click on that. It will open the below screen where you can see the message "Hello System Account" i.e. Logged in user name.

Observe one important thing is the URL where the app is running which is completely different compared to the site where we have deployed, that means your site will not get impacted by the app which you are going to deploy into that.
App web

You have option on the top header navigation to go back to the site.

The above "System Account" is displayed using below code which is using CSOM (Client Side Object Model).

We will see more about that in future articles.


In the below code whenever you open the app, document. ready function will get called which in turn call the getUserName function where it uses the  web.get_currentUser() method to get the current user details.

If the getUserName  function is successful then we are displaying the title of the current user by calling

onGetUserNameSuccess() function.


Note: you can't use server side code in SharePoint-hosted Apps.

In this post you will get basic understanding of app development in SharePoint 2013 using visual studio 2012.
Apps main purpose in SharePoint 2013 is to provide the specific functionality or information to a SharePoint site. While trying to develop your first App you might get lots of errors initially, so I am here to resolve those. The main aim of this post is to cover all possible errors and resolutions for those errors you might get during the development.
Once you develop these apps where you will store?. Before starting the app development you have to check what are the hosting models available in SharePoint 2013.
- See more at: http://www.sharepoint-journey.com/app-development-in-sharepoint.html#sthash.CYrlr5DJ.dpuf
In this post you will get basic understanding of app development in SharePoint 2013 using visual studio 2012.
Apps main purpose in SharePoint 2013 is to provide the specific functionality or information to a SharePoint site. While trying to develop your first App you might get lots of errors initially, so I am here to resolve those. The main aim of this post is to cover all possible errors and resolutions for those errors you might get during the development.
Once you develop these apps where you will store?. Before starting the app development you have to check what are the hosting models available in SharePoint 2013.
- See more at: http://www.sharepoint-journey.com/app-development-in-sharepoint.html#sthash.CYrlr5DJ.dpuf

0 comments:

Post a Comment