Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
private string appJsonInfo;
private AppDeclaration Apps;
// A class to hold JSON converted objects for Apps
private class AppDeclaration
public string appName;
public string appId;
public string clientsideId;
// Declare and create a Json Object for all Apps
public void DeclareAppIds
appJsonInfo = "[{appId: \"xxxxx-xxxx-xxxx-xxxx-xxxxxxxx\", appName: \"testApp\", clientsideId: \"xxxxxx-xxxx-xxxx-xxxx-xxxxxxxx\"}, " +
"{appId: \"xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx\", appName: \"testApp1\", clientsideId: \"xxxxxx-xxxx-xxxx-xxxxx-xxxxxx\"}, " +
"{appId: \"xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx\", appName: \"testApp2\", clientsideId: \"xxxxxx-xxxx-xxxx-xxxxx-xxxxxx\"}]";
Apps = JsonConvert.DeserializeObject<List<AppDeclaration>>(appJsonInfo);
public void AddExtensions(string listURL)
AppDeclaration App = appConfiguration.Apps.Find(app => app.appName.Contains("<app name>"));
Guid AppID = new Guid(App.clientsideId);
string AppName = App.appName;
using (ClientContext context = new ClientContext(<siteUrl>))
if (AppID != Guid.Empty)
context.Credentials = new SharePointOnlineCredentials(UserName, SecurePass);
List list = context.Web.GetListByUrl(<list URL>);
log.Info("Finding and Adding Extenstion to " + list.Title);
context.Load(list, t => t.UserCustomActions);
UserCustomActionCollection listExt = list.UserCustomActions;
bool AppPresent = false;
foreach (UserCustomAction customAcc in listExt)
if (customAcc.ClientSideComponentId == AppID)
tenancyAppPresent = true;
if (!tenancyAppPresent)
UserCustomAction customAction = list.UserCustomActions.Add();
customAction.ClientSideComponentId = AppID;
customAction.Location = "ClientSideExtension.ListViewCommandSet";
customAction.Name = AppName;
customAction.Title = AppName;
throw new Exception("System Error - App cannot be added as no App ID found");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment