/// <summary>
        /// </summary>
        private void bgw_AddActionAdv(object sender, DoWorkEventArgs e)
        {
            UserActionObjectAdv userActionObjAdv = 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.ExecuteQuery();
                    tcout("Site loaded", site.ServerRelativeUrl);

                    userActionObjAdv = new UserActionObjectAdv();

                    userActionObjAdv.name  = tbAdvName.Text.Trim();
                    userActionObjAdv.descr = tbAdvDescr.Text.Trim();
                    userActionObjAdv.seq   = GenUtil.SafeToInt(tbAdvSeq.Text.Trim());
                    if (userActionObjAdv.seq <= 0)
                    {
                        userActionObjAdv.seq = _defaultSeq;
                    }
                    userActionObjAdv.scriptSrc   = tbAdvScriptSrc.Text.Trim();
                    userActionObjAdv.scriptBlock = tbAdvScriptBlock.Text.Trim();

                    userActionObjAdv.commandUIExtension = tbAdvCmdUIExt.Text.Trim();
                    userActionObjAdv.group            = tbAdvGroup.Text.Trim();
                    userActionObjAdv.imageUrl         = tbAdvImageURL.Text.Trim();
                    userActionObjAdv.location         = tbAdvLocation.Text.Trim();
                    userActionObjAdv.registrationId   = tbAdvRegID.Text.Trim();
                    userActionObjAdv.registrationType = advRegType;

                    AddScriptAdv(ctx, site, web, ref userActionObjAdv);
                }
            }
            catch (Exception ex)
            {
                tcout(" *** ERROR", GetExcMsg(ex));
                ErrorOccurred = true;
            }

            e.Result = new List <object>()
            {
                userActionObjAdv
            };
        }
        /// <summary>
        /// </summary>
        private void AddScriptAdv(ClientContext ctx, Site site, Web web, ref UserActionObjectAdv ucaObj)
        {
            UserCustomAction uca = null;

            if (scope.IsEqual("Site Collection"))
            {
                uca = site.UserCustomActions.Add();
            }
            else
            {
                uca = web.UserCustomActions.Add();
            }

            if (!ucaObj.commandUIExtension.IsNull())
            {
                uca.CommandUIExtension = ucaObj.commandUIExtension;
            }

            if (!ucaObj.descr.IsNull())
            {
                uca.Description = ucaObj.descr;
            }

            if (!ucaObj.group.IsNull())
            {
                uca.Group = ucaObj.group;
            }

            if (!ucaObj.imageUrl.IsNull())
            {
                uca.ImageUrl = ucaObj.imageUrl;
            }

            if (!ucaObj.location.IsNull())
            {
                uca.Location = ucaObj.location;
            }

            if (!ucaObj.name.IsNull())
            {
                uca.Name = uca.Title = ucaObj.name;
            }

            if (!ucaObj.registrationId.IsNull())
            {
                uca.RegistrationId = ucaObj.registrationId;
            }

            if (!ucaObj.scriptBlock.IsNull())
            {
                uca.ScriptBlock = ucaObj.scriptBlock;
            }

            if (!ucaObj.scriptSrc.IsNull())
            {
                uca.ScriptSrc = ucaObj.scriptSrc;
            }

            uca.Sequence = ucaObj.seq;

            if (!ucaObj.Url.IsNull())
            {
                uca.Url = ucaObj.Url;
            }

            if (ucaObj.registrationType.IsEqual("ContentType"))
            {
                uca.RegistrationType = UserCustomActionRegistrationType.ContentType;
            }
            else if (ucaObj.registrationType.IsEqual("FileType"))
            {
                uca.RegistrationType = UserCustomActionRegistrationType.FileType;
            }
            else if (ucaObj.registrationType.IsEqual("List"))
            {
                uca.RegistrationType = UserCustomActionRegistrationType.List;
            }
            else if (ucaObj.registrationType.IsEqual("None"))
            {
                uca.RegistrationType = UserCustomActionRegistrationType.None;
            }
            else if (ucaObj.registrationType.IsEqual("ProgId"))
            {
                uca.RegistrationType = UserCustomActionRegistrationType.ProgId;
            }

            uca.Update();
            ctx.Load(uca, x => x.Id, x => x.Name);
            ctx.ExecuteQuery();

            ucaObj.id = uca.Id.ToString();

            tcout("Action added", ucaObj.id);
        }