private SPUserCustomAction GetCurrentCustomUserAction(object modelHost, UserCustomActionDefinition customActionModel
            , out SPUserCustomActionCollection 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()));
            }

            return userCustomActions.FirstOrDefault(a => !string.IsNullOrEmpty(a.Name) && a.Name.ToUpper() == customActionModel.Name.ToUpper());
        }
Example #2
0
        public static void AddECBMenu(this SPList list, string title, string location, string url, SPBasePermissions basePermission)
        {
            SPUserCustomActionCollection spUserCustomActionCollection = list.UserCustomActions;
            var spUserCustomAction = spUserCustomActionCollection.FirstOrDefault(p => p.Title == title);

            if (spUserCustomAction == null)
            {
                spUserCustomAction          = spUserCustomActionCollection.Add();
                spUserCustomAction.Location = location;
                spUserCustomAction.Sequence = 100;
                spUserCustomAction.Title    = title;
                if (basePermission != null)
                {
                    spUserCustomAction.Rights = basePermission;
                }
                spUserCustomAction.Url = url;
                spUserCustomAction.Update();
            }
        }
Example #3
0
        private SPUserCustomAction GetCurrentCustomUserAction(object modelHost, UserCustomActionDefinition customActionModel
                                                              , out SPUserCustomActionCollection 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()));
            }

            return(userCustomActions.FirstOrDefault(a => !string.IsNullOrEmpty(a.Name) && a.Name.ToUpper() == customActionModel.Name.ToUpper()));
        }