/// <summary> /// </summary> private void UpdateGrid(UserActionObject userActionObj) { int i = 0; int n = dataGridView1.Rows.Add(); dataGridView1.Rows[n].Cells[i++].Value = false; dataGridView1.Rows[n].Cells[i++].Value = userActionObj.id; dataGridView1.Rows[n].Cells[i++].Value = userActionObj.name; dataGridView1.Rows[n].Cells[i++].Value = userActionObj.descr; dataGridView1.Rows[n].Cells[i++].Value = userActionObj.seq.ToString(); dataGridView1.Rows[n].Cells[i++].Value = userActionObj.scriptSrc; dataGridView1.Rows[n].Cells[i++].Value = userActionObj.scriptBlock; }
/// <summary> /// </summary> private void bgw_AddAction(object sender, DoWorkEventArgs e) { UserActionObject userActionObj = null; try { var targetSite = new Uri(tbSiteUrl.Text.Trim()); using (ClientContext ctx = new ClientContext(targetSite)) { ctx.Credentials = BuildCreds(); FixCtxForMixedMode(ctx); Site site = ctx.Site; Web web = ctx.Web; ctx.Load(site, x => x.ServerRelativeUrl); ctx.Load(web, x => x.ServerRelativeUrl); ctx.ExecuteQuery(); tcout("Site loaded", site.ServerRelativeUrl); userActionObj = new UserActionObject(); userActionObj.name = tbActionName.Text.Trim(); userActionObj.descr = tbActionDescr.Text.Trim(); userActionObj.seq = GenUtil.SafeToInt(tbScriptSeq.Text.Trim()); if (userActionObj.seq <= 0) { userActionObj.seq = _defaultSeq; } userActionObj.scriptSrc = tbScriptSrc.Text.Trim(); userActionObj.scriptBlock = tbScriptBlock.Text.Trim(); AddScript(ctx, site, web, ref userActionObj); } } catch (Exception ex) { tcout(" *** ERROR", GetExcMsg(ex)); ErrorOccurred = true; } e.Result = new List <object>() { userActionObj }; }
/// <summary> /// </summary> private void AddScript(ClientContext ctx, Site site, Web web, ref UserActionObject ucaObj) { UserCustomAction uca = null; if (scope.IsEqual("Site Collection")) { uca = site.UserCustomActions.Add(); } else { uca = web.UserCustomActions.Add(); } uca.Location = "ScriptLink"; if (!ucaObj.scriptSrc.IsNull()) { uca.ScriptSrc = ucaObj.scriptSrc; } if (!ucaObj.scriptBlock.IsNull()) { uca.ScriptBlock = ucaObj.scriptBlock; } if (!ucaObj.descr.IsNull()) { uca.Description = ucaObj.descr; } if (!ucaObj.name.IsNull()) { uca.Title = uca.Name = ucaObj.name; } uca.Sequence = ucaObj.seq; uca.Update(); ctx.Load(uca, x => x.Id, x => x.Name); ctx.ExecuteQuery(); ucaObj.id = uca.Id.ToString(); tcout("Action added", ucaObj.id); }
/// <summary> /// </summary> private void AddScript(ClientContext ctx, Site site, ref UserActionObject userActionObj) { UserCustomAction spUserCustomAction = site.UserCustomActions.Add(); spUserCustomAction.Location = "ScriptLink"; if (!userActionObj.scriptSrc.IsNull()) { spUserCustomAction.ScriptSrc = userActionObj.scriptSrc; } if (!userActionObj.scriptBlock.IsNull()) { spUserCustomAction.ScriptBlock = userActionObj.scriptBlock; } if (!userActionObj.descr.IsNull()) { spUserCustomAction.Description = userActionObj.descr; } if (!userActionObj.name.IsNull()) { spUserCustomAction.Name = userActionObj.name; } spUserCustomAction.Sequence = userActionObj.seq; spUserCustomAction.Update(); ctx.Load(spUserCustomAction, x => x.Id, x => x.Name); ctx.ExecuteQuery(); userActionObj.id = spUserCustomAction.Id.ToString(); tcout("Action added", userActionObj.id); }