Last active
June 20, 2020 19:15
-
-
Save gautamdsheth/29e94b47fba0d94afe37a50febd46259 to your computer and use it in GitHub Desktop.
Install app to site collection using CSOM C# in SharePoint Online
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
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
I am not able to get AppManager class - below is the error:
The type or Namespace name "App manager" could not be found.