protected UserCustomAction GetCurrentCustomUserAction(object modelHost, UserCustomActionDefinition customActionModel) { UserCustomActionCollection userCustomActions = null; return(GetCurrentCustomUserAction(modelHost, customActionModel, out userCustomActions)); }
private void WireUpJSFileInternal(string scriptSource, string actionName, int sequence) { UserCustomActionCollection userCustomActions = GetCurrentUserCustomActionsDeclaredOnThisWeb(); bool alreadyPresent = false; foreach (UserCustomAction userCustomAction in userCustomActions) { if (!string.IsNullOrEmpty(userCustomAction.Name) && userCustomAction.Name == actionName) { alreadyPresent = true; break; } } if (!alreadyPresent) { // add it UserCustomAction action = userCustomActions.Add(); action.ScriptSrc = scriptSource; action.Location = "ScriptLink"; action.Name = actionName; action.Sequence = sequence; action.Update(); this.hostWebClientContextField.ExecuteQuery(); } }
public static Boolean ExistsJsLinkImplementation(ClientObject clientObject, String key) { UserCustomActionCollection existingActions = null; if (clientObject is Web) { existingActions = ((Web)clientObject).UserCustomActions; } else { existingActions = ((Site)clientObject).UserCustomActions; } clientObject.Context.Load(existingActions); clientObject.Context.ExecuteQueryRetry(); var actions = existingActions.ToArray(); foreach (var action in actions) { if (action.Name == key && action.Location == "ScriptLink") { return(true); } } return(false); }
/// <summary> /// Uninstalls all app specific assets and wirings up that were deployed to the host web. /// All global assets are left for safety. /// </summary> public void UninstallAssets() { // delete all app specific custom actions UserCustomActionCollection userCustomActions = this.GetCurrentUserCustomActionsDeclaredOnThisWeb(); List <UserCustomAction> userCustomActionsToDelete = new List <UserCustomAction>(); foreach (UserCustomAction userCustomAction in userCustomActions) { if (!string.IsNullOrEmpty(userCustomAction.Name) && userCustomAction.Name.StartsWith(this.appForSharePointInternalNameField)) { userCustomActionsToDelete.Add(userCustomAction); } } if (userCustomActionsToDelete.Count > 0) { foreach (UserCustomAction userCustomActionToDelete in userCustomActionsToDelete) { userCustomActionToDelete.DeleteObject(); } } // delete app specific folder (and all contents/subfolders) this.DeleteFolderRecursive("_apps/" + this.appForSharePointInternalNameField); this.hostWebClientContextField.ExecuteQuery(); }
private UserCustomAction GetCurrentCustomUserAction(object modelHost, UserCustomActionDefinition customActionModel , out UserCustomActionCollection userCustomActions) { if (modelHost is SiteModelHost) { userCustomActions = (modelHost as SiteModelHost).HostSite.UserCustomActions; } else if (modelHost is WebModelHost) { userCustomActions = (modelHost as WebModelHost).HostWeb.UserCustomActions; } else if (modelHost is ListModelHost) { userCustomActions = (modelHost as ListModelHost).HostList.UserCustomActions; } else { throw new Exception(string.Format("modelHost of type {0} is not supported.", modelHost.GetType())); } var context = userCustomActions.Context; context.Load(userCustomActions); context.ExecuteQueryWithTrace(); return(userCustomActions.FirstOrDefault(a => !string.IsNullOrEmpty(a.Name) && a.Name.ToUpper() == customActionModel.Name.ToUpper())); }
public SPOUserCustomActionCollection(UserCustomActionCollection userCustomActionCollection) { _userCustomActionCollection = userCustomActionCollection; foreach (var uca in userCustomActionCollection) { AddChild(new SPOUserCustomAction(uca)); } }
private void DeploySiteCustomAction(object modelHost, UserCustomActionDefinition model) { UserCustomActionCollection userCustomActions = null; var existingAction = GetCurrentCustomUserAction(modelHost, model, out userCustomActions); var context = userCustomActions.Context; InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, Object = null, ObjectType = typeof(UserCustomAction), ObjectDefinition = model, ModelHost = modelHost }); if (existingAction == null) { TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, "Processing new user custom action"); existingAction = userCustomActions.Add(); } else { TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing user custom action"); } MapCustomAction(existingAction, model); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = existingAction, ObjectType = typeof(UserCustomAction), ObjectDefinition = model, ModelHost = modelHost }); TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Calling existingAction.Update()"); existingAction.Update(); context.ExecuteQueryWithTrace(); }
private CustomActionCreator GetCustomActionCreator(ClientContext ctx, UserCustomActionCollection userCustomActions, string customActionName) { ctx.Load(userCustomActions, uca => uca.Where(ca => ca.Title == customActionName)); ctx.ExecuteQueryRetry(); if (userCustomActions.Count == 0) { return(null); } var userCustomAction = userCustomActions[0]; var newCreator = GetCreatorFromUserCustomAction(userCustomAction); return(newCreator); }
private UserCustomAction GetCurrentCustomUserAction(object modelHost, UserCustomActionDefinition customActionModel , out UserCustomActionCollection userCustomActions) { if (modelHost is SiteModelHost) userCustomActions = (modelHost as SiteModelHost).HostSite.UserCustomActions; else if (modelHost is WebModelHost) userCustomActions = (modelHost as WebModelHost).HostWeb.UserCustomActions; else if (modelHost is ListModelHost) userCustomActions = (modelHost as ListModelHost).HostList.UserCustomActions; else { throw new Exception(string.Format("modelHost of type {0} is not supported.", modelHost.GetType())); } var context = userCustomActions.Context; context.Load(userCustomActions); context.ExecuteQueryWithTrace(); return userCustomActions.FirstOrDefault(a => !string.IsNullOrEmpty(a.Name) && a.Name.ToUpper() == customActionModel.Name.ToUpper()); }
private void WalkCustomActions() { Web ww = ctx.Web; UserCustomActionCollection ucas = ww.UserCustomActions; ctx.Load(ucas); ctx.Load(ww); ctx.ExecuteQuery(); foreach (UserCustomAction uca in ucas) { ctx.Load(uca); ctx.ExecuteQuery(); System.Diagnostics.Trace.WriteLine(uca.Name); uca.ClientSideComponentProperties = "{\"FooterMessage\":\"This Site is External Facing.\"}"; uca.Update(); ctx.ExecuteQuery(); } }
public override IEnumerable <ReverseHostBase> ReverseHosts(ReverseHostBase parentHost, ReverseOptions options) { var result = new List <UserCustomActionReverseHost>(); var siteHost = parentHost as SiteReverseHost; var webHost = parentHost as WebReverseHost; var site = siteHost.HostSite; var web = siteHost.HostWeb; UserCustomActionCollection items = null; if (webHost != null) { web = webHost.HostWeb; items = web.UserCustomActions; } else if (siteHost != null) { items = site.UserCustomActions; } var context = siteHost.HostClientContext; context.Load(items); context.ExecuteQueryWithTrace(); result.AddRange(ApplyReverseFilters(items, options).ToArray().Select(i => { return(ModelHostBase.Inherit <UserCustomActionReverseHost>(parentHost, h => { h.HostUserCustomAction = i; })); })); return(result); }
/// <summary> /// </summary> private void bgw_DelSel(object sender, DoWorkEventArgs e) { var lstUserActionObjs = new List <UserActionObject>(); try { for (int i = 0; i < dataGridView1.Rows.Count; i++) { var k = 0; var userActionObj = new BandR.UserActionObject(); userActionObj.selected = Convert.ToBoolean(dataGridView1.Rows[i].Cells[k++].Value); userActionObj.id = dataGridView1.Rows[i].Cells[k++].Value.SafeTrim(); userActionObj.name = dataGridView1.Rows[i].Cells[k++].Value.SafeTrim(); userActionObj.descr = dataGridView1.Rows[i].Cells[k++].Value.SafeTrim(); userActionObj.seq = Convert.ToInt32(dataGridView1.Rows[i].Cells[k++].Value); userActionObj.scriptSrc = dataGridView1.Rows[i].Cells[k++].Value.SafeTrim(); userActionObj.scriptBlock = dataGridView1.Rows[i].Cells[k++].Value.SafeTrim(); lstUserActionObjs.Add(userActionObj); } var targetSite = new Uri(tbSiteUrl.Text.Trim()); using (ClientContext ctx = new ClientContext(targetSite)) { ctx.Credentials = BuildCreds(); FixCtxForMixedMode(ctx); Site site = ctx.Site; ctx.Load(site, x => x.ServerRelativeUrl); ctx.ExecuteQuery(); tcout("Site loaded", site.ServerRelativeUrl); UserCustomActionCollection spActions = null; if (scope.IsEqual("Site Collection")) { spActions = ctx.Site.UserCustomActions; } else { spActions = ctx.Web.UserCustomActions; } ctx.Load(spActions); ctx.ExecuteQuery(); tcout("UserCustomActions Count", spActions.Count); for (int i = spActions.Count - 1; i >= 0; i--) { var curSpAction = spActions[i]; if (lstUserActionObjs.Any(x => Guid.Parse(x.id) == curSpAction.Id && x.selected)) { curSpAction.DeleteObject(); lstUserActionObjs.RemoveAll(x => Guid.Parse(x.id) == curSpAction.Id && x.selected); tcout("Deleting", curSpAction.Id, curSpAction.Name); } } if (ctx.HasPendingRequest) { ctx.ExecuteQuery(); tcout("Action(s) deleted."); } } } catch (Exception ex) { tcout(" *** ERROR", GetExcMsg(ex)); ErrorOccurred = true; } e.Result = new List <object>() { lstUserActionObjs }; }
/// <summary> /// </summary> private void bgw_LoadActions(object sender, DoWorkEventArgs e) { var lstUserActionObjs = new List <UserActionObject>(); try { var targetSite = new Uri(tbSiteUrl.Text.Trim()); using (ClientContext ctx = new ClientContext(targetSite)) { ctx.Credentials = BuildCreds(); FixCtxForMixedMode(ctx); Site site = ctx.Site; ctx.Load(site, x => x.ServerRelativeUrl); ctx.ExecuteQuery(); tcout("Site loaded", site.ServerRelativeUrl); UserCustomActionCollection spActions = null; if (scope.IsEqual("Site Collection")) { spActions = ctx.Site.UserCustomActions; } else { spActions = ctx.Web.UserCustomActions; } ctx.Load(spActions); ctx.ExecuteQuery(); tcout("UserCustomActions Count", spActions.Count); var spActionsSorted = spActions.ToList <UserCustomAction>().OrderBy(x => x.Sequence).ThenBy(x => x.Name); foreach (UserCustomAction spAction in spActionsSorted) { var userActionObj = new BandR.UserActionObject(); userActionObj.id = spAction.Id.ToString(); userActionObj.name = spAction.Name; userActionObj.descr = spAction.Description; userActionObj.seq = spAction.Sequence; userActionObj.scriptBlock = spAction.ScriptBlock; userActionObj.scriptSrc = spAction.ScriptSrc; lstUserActionObjs.Add(userActionObj); tcout("-----------------------------"); tcout("Found UserCustomAction:"); tcout(" - Id", spAction.Id.ToString()); tcout(" - Name", spAction.Name); tcout(" - Title", spAction.Title); tcout(" - CommandUIExtension", spAction.CommandUIExtension); tcout(" - Description", spAction.Description); tcout(" - Group", spAction.Group); tcout(" - ImageUrl", spAction.ImageUrl); tcout(" - Location", spAction.Location); tcout(" - RegistrationId", spAction.RegistrationId); tcout(" - RegistrationType", spAction.RegistrationType.ToString()); tcout(" - Scope", spAction.Scope.ToString()); tcout(" - ScriptBlock", spAction.ScriptBlock); tcout(" - ScriptSrc", spAction.ScriptSrc); tcout(" - Sequence", spAction.Sequence); tcout(" - Url", spAction.Url); } } } catch (Exception ex) { tcout(" *** ERROR", GetExcMsg(ex)); ErrorOccurred = true; } e.Result = new List <object>() { lstUserActionObjs }; }
private void bgw_SaveSelChanges(object sender, DoWorkEventArgs e) { var lstUserActionObjs = new List <UserActionObject>(); try { for (int i = 0; i < dataGridView1.Rows.Count; i++) { var k = 0; var userActionObj = new BandR.UserActionObject(); userActionObj.selected = Convert.ToBoolean(dataGridView1.Rows[i].Cells[k++].Value); userActionObj.id = dataGridView1.Rows[i].Cells[k++].Value.SafeTrim(); userActionObj.name = dataGridView1.Rows[i].Cells[k++].Value.SafeTrim(); userActionObj.descr = dataGridView1.Rows[i].Cells[k++].Value.SafeTrim(); userActionObj.seq = Convert.ToInt32(dataGridView1.Rows[i].Cells[k++].Value); userActionObj.scriptSrc = dataGridView1.Rows[i].Cells[k++].Value.SafeTrim(); userActionObj.scriptBlock = dataGridView1.Rows[i].Cells[k++].Value.SafeTrim(); lstUserActionObjs.Add(userActionObj); } var targetSite = new Uri(tbSiteUrl.Text.Trim()); using (ClientContext ctx = new ClientContext(targetSite)) { ctx.Credentials = BuildCreds(); FixCtxForMixedMode(ctx); Site site = ctx.Site; ctx.Load(site, x => x.ServerRelativeUrl); ctx.ExecuteQuery(); tcout("Site loaded", site.ServerRelativeUrl); UserCustomActionCollection spActions = null; if (scope.IsEqual("Site Collection")) { spActions = ctx.Site.UserCustomActions; } else { spActions = ctx.Web.UserCustomActions; } ctx.Load(spActions); ctx.ExecuteQuery(); tcout("UserCustomActions Count", spActions.Count); for (int i = spActions.Count - 1; i >= 0; i--) { var changed = false; var curSpAction = spActions[i]; var curGridAction = lstUserActionObjs.FirstOrDefault(x => Guid.Parse(x.id) == curSpAction.Id); // && x.selected if (curGridAction != null) { if (curGridAction.scriptSrc.IsNull() && curGridAction.scriptBlock.IsNull()) { // invalid option tcout(" *** Skipping update, cannot save CustomAction with both ScriptSrc and ScriptBlock filled", curGridAction.id, curGridAction.name); continue; } if (curSpAction.Name != curGridAction.name && !curGridAction.name.IsNull()) { curSpAction.Name = curGridAction.name; changed = true; } if (curSpAction.Description != curGridAction.descr) { curSpAction.Description = curGridAction.descr.IsNull() ? null : curGridAction.descr; changed = true; } if (curSpAction.Sequence != curGridAction.seq) { curSpAction.Sequence = curGridAction.seq <= 0 ? _defaultSeq : curGridAction.seq; changed = true; } if (curSpAction.ScriptSrc != curGridAction.scriptSrc) { curSpAction.ScriptSrc = curGridAction.scriptSrc.IsNull() ? null : curGridAction.scriptSrc; changed = true; } if (curSpAction.ScriptBlock != curGridAction.scriptBlock) { curSpAction.ScriptBlock = curGridAction.scriptBlock.IsNull() ? null : curGridAction.scriptBlock; changed = true; } if (changed) { curSpAction.Update(); } } } if (ctx.HasPendingRequest) { ctx.ExecuteQuery(); tcout("Action(s) updated."); } } } catch (Exception ex) { tcout(" *** ERROR", GetExcMsg(ex)); ErrorOccurred = true; } e.Result = new List <object>() { lstUserActionObjs }; }
private static void RemoveScriptLinksFromHostWeb(ClientContext clientContext, UserCustomActionCollection existingActions) { var actions = existingActions.ToArray(); foreach (var action in actions) { if (action.Location.Equals("ScriptLink") && (action.Description.Equals("weeknumberJQuery") || action.Description.Equals("weeknumberScript"))) { action.DeleteObject(); } } clientContext.ExecuteQuery(); }
public Configurations GetConfigurations(ClientContext clientContext, out UserCustomActionCollection customActions) { Configurations configurations = new Configurations(); customActions = clientContext.Site.UserCustomActions; clientContext.Load(customActions); clientContext.ExecuteQuery(); configurations.ScriptLinks = new List<ScriptLinkAction>(); configurations.CSSLinks = new List<ScriptLinkAction>(); foreach (UserCustomAction customAction in customActions) { if (customAction.Title == HEADER) { configurations.HeaderScripts = customAction.ScriptBlock; } else if (customAction.Title != LOAD_SCRIPT) { if (customAction.Title.StartsWith(GENESIS_CSS) && !String.IsNullOrEmpty(customAction.ScriptBlock)) { string scriptSrc = customAction.ScriptBlock.Split(new string[] { "LoadCSS('" }, StringSplitOptions.None)[1]; string exclude = ""; if (scriptSrc.Contains(",")) { //means we have an Exclude var scriptScrSplit = scriptSrc.Split(new string[] { "'," }, StringSplitOptions.None); scriptSrc = scriptScrSplit[0]; exclude = scriptScrSplit[1].Split(new string[] { "');" }, StringSplitOptions.None)[0].Replace("'", ""); } else { scriptSrc = scriptSrc.Split(new string[] { "');" }, StringSplitOptions.None)[0]; } configurations.CSSLinks.Add(new ScriptLinkAction { Id = customAction.Id.ToString(), Title = customAction.Title.Replace(GENESIS_CSS, ""), ScriptSrc = scriptSrc, Excludes = exclude, Sequence = customAction.Sequence.ToString(), Type = CSS }); } else if (customAction.Title.StartsWith(GENESIS_JS) && !String.IsNullOrEmpty(customAction.ScriptBlock)) { string scriptSrc = customAction.ScriptBlock.Split(new string[] { "LoadScript('" }, StringSplitOptions.None)[1]; string exclude = ""; string dependency = ""; var useSod = false; if (scriptSrc.Contains(",")) { //means we have an Exclude and/or a Dependency var scriptScrSplit = scriptSrc.Split(new string[] { "'," }, StringSplitOptions.None); scriptSrc = scriptScrSplit[0]; if (scriptScrSplit.Length == 2) { exclude = scriptScrSplit[1].Split(new string[] { "');" }, StringSplitOptions.None)[0].Replace("'", ""); } else if (scriptScrSplit.Length == 3) { exclude = scriptScrSplit[1].Replace("'", ""); dependency = scriptScrSplit[2].Split(new string[] { "');" }, StringSplitOptions.None)[0].Replace("'", ""); } else if (scriptScrSplit.Length == 5) { exclude = scriptScrSplit[1].Replace("'", ""); dependency = scriptScrSplit[2].Replace("'", ""); var title = scriptScrSplit[3].Replace("'", ""); var sod = scriptScrSplit[4].Split(new string[] { ");" }, StringSplitOptions.None)[0]; useSod = sod == "true"; } } else { scriptSrc = scriptSrc.Split(new string[] { "');" }, StringSplitOptions.None)[0]; } configurations.ScriptLinks.Add(new ScriptLinkAction { Id = customAction.Id.ToString(), Title = customAction.Title.Replace(GENESIS_JS, ""), ScriptSrc = scriptSrc, SOD = useSod, Excludes = exclude, Dependency = dependency, Sequence = customAction.Sequence.ToString(), Type = JS }); } } } return configurations; }
/// <summary> /// Analyses the user custom actions /// </summary> /// <param name="userCustomActions">UserCustomAction collection</param> /// <param name="siteCollectionUrl">Url of the site collection</param> /// <param name="siteUrl">Url of the site</param> /// <returns>Collection of UserCustomActions that are not respected in the modern UI</returns> public static List <UserCustomActionResult> Analyze(this UserCustomActionCollection userCustomActions, string siteCollectionUrl, string siteUrl) { List <UserCustomActionResult> issues = new List <UserCustomActionResult>(); foreach (UserCustomAction uca in userCustomActions) { bool add = false; UserCustomActionResult result = new UserCustomActionResult() { SiteURL = siteUrl, SiteColUrl = siteCollectionUrl, Title = uca.Title, Name = uca.Name, Location = uca.Location, RegistrationType = uca.RegistrationType, RegistrationId = uca.RegistrationId, ScriptBlock = "", ScriptSrc = "", }; if (!string.IsNullOrEmpty(uca.Location)) { if (!(uca.Location.Equals("EditControlBlock", StringComparison.InvariantCultureIgnoreCase) || uca.Location.StartsWith("ClientSideExtension.", StringComparison.InvariantCultureIgnoreCase) || uca.Location.Equals("CommandUI.Ribbon", StringComparison.InvariantCultureIgnoreCase))) { add = true; result.ScriptBlock = uca.ScriptBlock != null ? uca.ScriptBlock : ""; result.ScriptSrc = uca.ScriptSrc != null ? uca.ScriptSrc : ""; result.Problem = "InvalidLocation"; } } if (!string.IsNullOrEmpty(uca.CommandUIExtension)) { XmlDocument doc = new XmlDocument(); string xmlString = uca.CommandUIExtension; xmlString = xmlString.Replace("http://schemas.microsoft.com/sharepoint/", ""); doc.LoadXml(xmlString); XmlNodeList handlers = doc.SelectNodes("/CommandUIExtension/CommandUIHandlers/CommandUIHandler"); foreach (XmlNode handler in handlers) { if (handler.Attributes["CommandAction"] != null && handler.Attributes["CommandAction"].Value.ToLower().Contains("javascript")) { result.CommandAction = handler.Attributes["CommandAction"].Value; result.Problem = !String.IsNullOrEmpty(result.Problem) ? $"{result.Problem}, JavaScriptEmbedded" : "JavaScriptEmbedded"; add = true; break; } } } if (add) { issues.Add(result); } } return(issues); }
private static bool AddCustomActionImplementation(ClientObject clientObject, CustomActionEntity customAction) { UserCustomAction targetAction = null; UserCustomActionCollection existingActions = null; if (clientObject is Web) { var web = (Web)clientObject; existingActions = web.UserCustomActions; web.Context.Load(existingActions); web.Context.ExecuteQueryRetry(); targetAction = web.UserCustomActions.FirstOrDefault(uca => uca.Name == customAction.Name); } else { var site = (Site)clientObject; existingActions = site.UserCustomActions; site.Context.Load(existingActions); site.Context.ExecuteQueryRetry(); targetAction = site.UserCustomActions.FirstOrDefault(uca => uca.Name == customAction.Name); } if (targetAction == null) { // If we're removing the custom action then we need to leave when not found...else we're creating the custom action if (customAction.Remove) { return(true); } else { targetAction = existingActions.Add(); } } else if (customAction.Remove) { targetAction.DeleteObject(); clientObject.Context.ExecuteQueryRetry(); return(true); } targetAction.Name = customAction.Name; targetAction.Description = customAction.Description; targetAction.Location = customAction.Location; if (customAction.Location == JavaScriptExtensions.SCRIPT_LOCATION) { targetAction.ScriptBlock = customAction.ScriptBlock; targetAction.ScriptSrc = customAction.ScriptSrc; } else { targetAction.Sequence = customAction.Sequence; targetAction.Url = customAction.Url; targetAction.Group = customAction.Group; targetAction.Title = customAction.Title; targetAction.ImageUrl = customAction.ImageUrl; if (customAction.RegistrationId != null) { targetAction.RegistrationId = customAction.RegistrationId; } if (customAction.CommandUIExtension != null) { targetAction.CommandUIExtension = customAction.CommandUIExtension; } if (customAction.Rights != null) { targetAction.Rights = customAction.Rights; } if (customAction.RegistrationType.HasValue) { targetAction.RegistrationType = customAction.RegistrationType.Value; } } targetAction.Update(); if (clientObject is Web) { var web = (Web)clientObject; web.Context.Load(web, w => w.UserCustomActions); web.Context.ExecuteQueryRetry(); } else { var site = (Site)clientObject; site.Context.Load(site, s => s.UserCustomActions); site.Context.ExecuteQueryRetry(); } return(true); }
private void AddCustomActionsToResult(UserCustomActionCollection coll, ref ConcurrentStack <CustomActionsResult> customActions, ref ConcurrentDictionary <string, CustomizationResult> customizationResults, ref ConcurrentStack <UIExperienceScanError> UIExpScanErrors, string listUrl = "", string listTitle = "") { var baseUri = new Uri(this.url); var webAppUrl = baseUri.Scheme + "://" + baseUri.Host; foreach (UserCustomAction uca in coll) { try { bool add = false; CustomActionsResult result = new CustomActionsResult() { SiteUrl = this.url, Url = !String.IsNullOrEmpty(listUrl) ? $"{webAppUrl}{listUrl}" : this.url, SiteColUrl = this.siteColUrl, ListTitle = listUrl, Title = uca.Title, Name = uca.Name, Location = uca.Location, RegistrationType = uca.RegistrationType, RegistrationId = uca.RegistrationId, CommandActions = "", //ImageMaps = "", ScriptBlock = "", ScriptSrc = "", }; if (!(uca.Location.Equals("EditControlBlock", StringComparison.InvariantCultureIgnoreCase) || uca.Location.StartsWith("ClientSideExtension.", StringComparison.InvariantCultureIgnoreCase) || uca.Location.Equals("CommandUI.Ribbon", StringComparison.InvariantCultureIgnoreCase))) { add = true; result.ScriptBlock = uca.ScriptBlock != null ? uca.ScriptBlock : ""; result.ScriptSrc = uca.ScriptSrc != null ? uca.ScriptSrc : ""; result.Problem = "Invalid location"; } // List scoped custom actions registered to a specific listid do work in "modern" //Guid registrationIDGuid; //if (Guid.TryParse(uca.RegistrationId, out registrationIDGuid)) //{ // result.Problem = !String.IsNullOrEmpty(result.Problem) ? $"{result.Problem}, Specific list registration" : "Specific list registration"; // add = true; //} if (!string.IsNullOrEmpty(uca.CommandUIExtension)) { XmlDocument doc = new XmlDocument(); string xmlString = uca.CommandUIExtension; xmlString = xmlString.Replace("http://schemas.microsoft.com/sharepoint/", ""); doc.LoadXml(xmlString); XmlNodeList handlers = doc.SelectNodes("/CommandUIExtension/CommandUIHandlers/CommandUIHandler"); foreach (XmlNode handler in handlers) { if (handler.Attributes["CommandAction"] != null && handler.Attributes["CommandAction"].Value.ToLower().Contains("javascript")) { result.CommandActions = "JS Found"; result.Problem = !String.IsNullOrEmpty(result.Problem) ? $"{result.Problem}, JavaScript embedded" : "JavaScript embedded"; add = true; break; } } // Skipping image maps as these UCA do show, but without image //XmlNodeList imageButtons = doc.SelectNodes("//Button"); //foreach (XmlNode btn in imageButtons) //{ // //Image16by16Left, Image16by16Top, Image32by32Left, Image32by32Top // if (btn.Attributes["Image16by16"] != null || btn.Attributes["Image32by32"] != null) // { // result.ImageMaps = "Found"; // result.Problem = !String.IsNullOrEmpty(result.Problem) ? $"{result.Problem}, ImageMap used" : "ImageMap used"; // add = true; // break; // } //} } if (add) { customActions.Push(result); if (customizationResults.ContainsKey(result.Url)) { var customizationResult = customizationResults[result.Url]; customizationResult.IgnoredCustomAction = true; if (!customizationResults.TryUpdate(result.Url, customizationResult, customizationResult)) { UIExperienceScanError error = new UIExperienceScanError() { Error = $"Could not update custom action scan result for {customizationResult.Url}", SiteURL = this.url, SiteColUrl = this.siteColUrl }; UIExpScanErrors.Push(error); Console.WriteLine($"Could not update custom action scan result for {customizationResult.Url}"); } } else { var customizationResult = new CustomizationResult() { SiteUrl = result.SiteUrl, Url = result.Url, SiteColUrl = this.siteColUrl, IgnoredCustomAction = true }; if (!customizationResults.TryAdd(customizationResult.Url, customizationResult)) { UIExperienceScanError error = new UIExperienceScanError() { Error = $"Could not add custom action scan result for {customizationResult.Url}", SiteURL = url, SiteColUrl = siteColUrl }; UIExpScanErrors.Push(error); Console.WriteLine($"Could not add custom action scan result for {customizationResult.Url}"); } } } } catch (Exception ex) { UIExperienceScanError error = new UIExperienceScanError() { Error = ex.Message, SiteURL = this.url, SiteColUrl = this.siteColUrl }; UIExpScanErrors.Push(error); Console.WriteLine("Error for site {1}: {0}", ex.Message, this.url); } } }
private static void RemoveScriptLinksFromHostWeb(ClientContext clientContext, UserCustomActionCollection existingActions) { var actions = existingActions.ToArray(); foreach (var action in actions) { if (action.Location.Equals("ScriptLink") && (action.Description.Equals("copyPasteImagesJQuery") || action.Description.Equals("copyPasteImagesScript"))) { action.DeleteObject(); } } clientContext.ExecuteQuery(); }