Office 365 Dev Tip - Getting Add-in (App) Information for Add-ins (Apps) on a specific Web
Here’s yet another quick tip for the CSOM developer in SharePoint online. I came across a discussion about retrieving information about which apps were used/installed on a certain site. There’s a lot of people who want a simple indicator, notification/alert or list when new apps are deployed or removed globally and don’t want to complicate things. Well, here’s an easy way to find out exactly which apps are installed on a specific web.
Oh an by the way it’s old news now, but Apps are called Add-ins. I’ll try to refer to them as Add-ins in the future, but don’t blame me if I use the word App once or twice more :-)
Pre-requisites
In order to run the code in the snippet you should already have:
- Installed the SharePoint Online CSOM NuGet into your Visual Studio project
- Installed the Office 365 Patterns and Practices NuGet into your Visual Studio project
Code Snippet
When retrieving information about a specific Add-in, you’ll get an AppInstance object returned with information about the Add-in (or App, or whatever you want to call it..)
using (ClientContext context = new ClientContext("https://yourdomain.sharepoint.com/sites/YourSiteCollection/YourWeb"))
{
Web web = context.Web;
web.Context.Load(web);
web.Context.ExecuteQueryRetry();
// We'll get the Apps.. Sorry Add-ins from the... AppCatalog :-)
var addInInstance = AppCatalog.GetAppInstances(context, web);
addInInstance.Context.Load(addInInstance);
addInInstance.Context.ExecuteQueryRetry();
Debug.WriteLine("Add-in Instances on this site: " + addInInstance.Count);
foreach (var appInstance in addInInstance)
{
// You can now get all the information about your appInstance object(s)
Debug.WriteLine("APP INSTANCE: " + appInstance.Title);
Debug.WriteLine("Status: " + appInstance.Status);
Debug.WriteLine("Start Page: " + appInstance.StartPage);
Debug.WriteLine("App Id: " + appInstance.Id);
Debug.WriteLine(" ");
}
}
With the aforementioned snippet, you’ll get all the Add-in instances (well, they’re still called AppInstances in the object model, but you get the point..) – now you can get all the required information about your apps using the returned results.
Here’s a list of all the properties you can get using the AppInstance object, including their accessors (get/set):
public string AppPrincipalId { get; }
public string AppWebFullUrl { get; }
public Guid Id { get; }
public string ImageFallbackUrl { get; }
public string ImageUrl { get; }
public bool InError { get; }
public byte[] PackageFingerprint { get; }
public Guid ProductId { get; }
public string RemoteAppUrl { get; }
public string SettingsPageUrl { get; }
public Guid SiteId { get; }
public string StartPage { get; }
public AppInstanceStatus Status { get; }
public string Title { get; }
public Guid WebId { get; }
As always, if you just want to do a quick check and don’t want to implement this as part of a solution/service/pattern then you could use the SharePoint Client Browser which has been created by SharePoint MCM Bram de Jager.
Running my code snippet above or using the Client Browser will yield the same result, just display them differently. Here’s an example of what an App Instance could look like, and the properties you’ll be able to see:
[![image](GHOST_URL/content/imaget/content/images/2015/07/image1.png)
With that said, it is very easy to get the information about your apps using CSOM with SharePoint Online / Office 365. (Yes, it’s just as easy on-premises of course).
Since people asked for it, here it is. Enjoy.
Recent comments