7

Can anyone suggest me on how to use SP.AppCatalog() in JSOM or CSOM and get the all apps in AppCatalog, Not AppInstances..

  • Any reason why you don't want to install the apps via the Sharepoint UI? – Stephen Feb 12 '14 at 14:02
  • Stephen- Idea is.. I want to deploy all apps at a time into the app catalog, so I thought CSOM with Powershell cmdlets is a good idea.. – kart Feb 13 '14 at 5:27
2

Not verified. But the AppCatalog is a SharePoint Library, i think you just have to add the *.app files to this list for deployment. there are plenty examaples of how to add a file to a library. Rest of the internal installation processing is automatically done by eventreceivers or workflows, i guess.

Installing might eventually be the bigger problem, atm i am not aware of a function which do this, but i think there should be one.

2

SharePoint CSOM API exposes the following methods:

How to deploy (upload & install) SharePoint App via CSOM

/// <summary>
/// Deploy SP App 
/// </summary>
/// <param name="context">Client context</param>
/// <param name="appFullPath">Full path to app file (.app)</param>
/// <returns></returns>
private static AppInstance DeployApp(ClientContext context, string appFullPath)
{
    using (var packageStream = System.IO.File.OpenRead(appFullPath))
    {
       var appInstance = context.Web.LoadAndInstallApp(packageStream);
       context.Load(appInstance);
       context.ExecuteQuery();
       return appInstance;
    }
 }

Usage

The following example demonstrates how to deploy SP App into SharePoint Online

using (var ctx = new ClientContext(url))
{              
      ctx.Credentials = new SharePointOnlineCredentials(userName, securePassword);
      var appInstance = DeployApp(ctx, @"C:\Packages\SPApp.app");
      if (appInstance != null && appInstance.Status == AppInstanceStatus.Initialized)
      {
          Console.WriteLine("App was installed.");
      }
 }

Retrieve App instances

using (var ctx = new ClientContext(webUrl))
{
    ctx.Credentials = CreateSPOCredentials(userName, password);

    var appInstances = AppCatalog.GetAppInstances(ctx, ctx.Web);
    ctx.Load(appInstances);
    ctx.ExecuteQuery();
    foreach (var appInstance in appInstances)
    {
        Console.WriteLine(appInstance.Title);
    }
 }
1

Apps can't be installed using CSOM or JSOM. Powershell is good choice.

Some links:

1

@kosikovec i doubt it is possible through powershell if you are looking at sharepoint online.There are no powershell scripts for app deployment to sharpeoint online

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.