Hello guys,
Here I am writing a small post on how to get the apps from a SharePoint Online site. The property "Status" of the AppInstance class tells us the app's status like whether it is installed/uninstalling/disabled etc..
Here I took a console app with managed CSOM code.
Here is the output :
If you observe the above code, we have created a object called appInstanceCollection for the ClientObjectCollection class. It needs ClientRuntimeContext and the web.
The ClientRuntimeContext represents the runtime context for accessing data from remote objects and invoking methods on remote objects. This can be safely typecasted from ClientContext class as shown above.
Note : In the new version of the CSOM dll you can find a new method called "GetAppDetails()" from the APPcatalog class. Please refer this link.
Hope this helps,
-Purna
Here I am writing a small post on how to get the apps from a SharePoint Online site. The property "Status" of the AppInstance class tells us the app's status like whether it is installed/uninstalling/disabled etc..
Here I took a console app with managed CSOM code.
- string siteUrl = "https://msplab.sharepoint.com/sites/SPOLPUB/";
- string username = "purna@msplab.onmicrosoft.com";
- string password = "mspcloud";
- // Ref: Microsoft.SharePoint.Client
- ClientContext ctx = new ClientContext(siteUrl);
- // Ref :System.Security
- SecureString encryptedSecureString = new SecureString();
- password.ToList().ForEach(encryptedSecureString.AppendChar);
- ctx.Credentials = new SharePointOnlineCredentials(username, encryptedSecureString);
- // Ref: Microsoft.SharePoint.Client
- Site site = ctx.Site;
- ctx.Load(site);
- ctx.ExecuteQuery();
- Console.WriteLine("Successfully Connected to Site "+site.Url);
- Console.WriteLine("Loading Web.. ");
- Web web = ctx.Web;
- ctx.Load(web, w => w.Url);
- ctx.ExecuteQuery();
- Console.WriteLine("Web Loaded.." + web.Url);
- Console.WriteLine("Getting AppInstance Collection ...");
- //CRC is from CC, so typecasting from cc
- ClientRuntimeContext ctxRuntime = (ClientContext)web.Context;
- //Getting appinstances from appcatalog with webcontext
- ClientObjectCollection appInstanceCollection =AppCatalog.GetAppInstances(ctxRuntime, web);
- ctxRuntime.Load(appInstanceCollection);
- ctxRuntime.ExecuteQuery();
- Console.WriteLine("Got AppInstance Collection...");
- foreach (AppInstance appinstance in appInstanceCollection)
- {
- ctxRuntime.Load(appinstance);
- ctxRuntime.ExecuteQuery();
- Console.WriteLine("==================Retrieving App Details =================");
- Console.WriteLine("App Title: " + appinstance.Title);
- Console.WriteLine("Principle Id: " + appinstance.AppPrincipalId);
- Console.WriteLine("Web Url: " + appinstance.AppWebFullUrl);
- Console.WriteLine("Start Page: " + appinstance.StartPage);
- Console.WriteLine("Installation Status: " + appinstance.Status);
- Console.WriteLine("Remote App Url: " + appinstance.RemoteAppUrl);
- Console.WriteLine("Settings Page: " + appinstance.SettingsPageUrl);
- Console.WriteLine("Error Details: " + appinstance.GetErrorDetails());
- Console.WriteLine("==================Completed App Details =================");
- }
- Console.WriteLine("Completed...");
- Console.ReadLine();
Here is the output :
If you observe the above code, we have created a object called appInstanceCollection for the ClientObjectCollection class. It needs ClientRuntimeContext and the web.
The ClientRuntimeContext represents the runtime context for accessing data from remote objects and invoking methods on remote objects. This can be safely typecasted from ClientContext class as shown above.
Note : In the new version of the CSOM dll you can find a new method called "GetAppDetails()" from the APPcatalog class. Please refer this link.
Hope this helps,
-Purna
Nice.thanks.
ReplyDelete