Skip to content

Instantly share code, notes, and snippets.

@gautamdsheth
Last active June 20, 2020 19:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gautamdsheth/29e94b47fba0d94afe37a50febd46259 to your computer and use it in GitHub Desktop.
Save gautamdsheth/29e94b47fba0d94afe37a50febd46259 to your computer and use it in GitHub Desktop.
Install app to site collection using CSOM C# in SharePoint Online
string webUrl = "https://tenant-name.sharepoint.com/sites/test/";
string username = "user.name@tenantname.onmicrosoft.com";
string password = "password";
SecureString secureString = new SecureString();
password.ToList().ForEach(secureString.AppendChar);
var credentials = new SharePointOnlineCredentials(username, secureString);
using (ClientContext ctx = new ClientContext(webUrl))
{
ctx.Credentials = credentials;
var appManager = new AppManager(ctx);
var apps = appManager.GetAvailable();
var chartsApp = apps.Where(a => a.Title == "Charts 365").FirstOrDefault();
var installApp = appManager.Install(chartsApp);
//or Install the app async
var installAppAsync = await appManager.InstallAsync(chartsApp);
}
@lovethakker02
Copy link

I am not able to get AppManager class - below is the error:
The type or Namespace name "App manager" could not be found.

@lovethakker02
Copy link

I was able to get it once I installed SharePointPnPCoreOnline from below link:
https://www.nuget.org/packages/SharePointPnPCoreOnline/

And I need to add below name space in code file
using Microsoft.SharePoint.Client;
using OfficeDevPnP.Core.ALM;
using OfficeDevPnP;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment