コード例 #1
0
        protected virtual void ProcessLocalization(SPUserCustomAction obj, UserCustomActionDefinition definition)
        {
            if (definition.TitleResource.Any())
            {
                foreach (var locValue in definition.TitleResource)
                {
                    LocalizationService.ProcessUserResource(obj, obj.TitleResource, locValue);
                }
            }

            if (definition.DescriptionResource.Any())
            {
                foreach (var locValue in definition.DescriptionResource)
                {
                    LocalizationService.ProcessUserResource(obj, obj.DescriptionResource, locValue);
                }
            }

            if (definition.CommandUIExtensionResource.Any())
            {
                foreach (var locValue in definition.CommandUIExtensionResource)
                {
                    LocalizationService.ProcessUserResource(obj, obj.CommandUIExtensionResource, locValue);
                }
            }
        }
コード例 #2
0
        public SPUserCustomActionInstance(ObjectInstance prototype, SPUserCustomAction userCustomAction)
            : this(prototype)
        {
            if (userCustomAction == null)
            {
                throw new ArgumentNullException("userCustomAction");
            }

            m_userCustomAction = userCustomAction;
        }
コード例 #3
0
 private void MapCustomAction(SPUserCustomAction existringAction, UserCustomActionDefinition customAction)
 {
     existringAction.Description = customAction.Description;
     existringAction.Group = customAction.Group;
     existringAction.Location = customAction.Location;
     existringAction.Name = customAction.Name;
     existringAction.ScriptBlock = customAction.ScriptBlock;
     existringAction.ScriptSrc = customAction.ScriptSrc;
     existringAction.Title = customAction.Title;
 }
コード例 #4
0
 private void MapCustomAction(SPUserCustomAction existringAction, UserCustomActionDefinition customAction)
 {
     existringAction.Description = customAction.Description;
     existringAction.Group       = customAction.Group;
     existringAction.Location    = customAction.Location;
     existringAction.Name        = customAction.Name;
     existringAction.ScriptBlock = customAction.ScriptBlock;
     existringAction.ScriptSrc   = customAction.ScriptSrc;
     existringAction.Title       = customAction.Title;
 }
コード例 #5
0
        /// <summary>
        /// Removes a custom action from a web
        /// </summary>
        /// <param name="web">The SharePoint web</param>
        /// <param name="actionName">The ID for the custom action</param>
        public static void DeleteCustomAction(this SPWeb web, string actionName)
        {
            Guid customActionId = GetCustomActionIdForName(web, actionName);

            if (customActionId != default(Guid))
            {
                SPUserCustomAction customAction = web.UserCustomActions[customActionId];
                customAction.Delete();
                web.Update();
            }
        }
コード例 #6
0
        private void MapCustomAction(SPUserCustomAction existringAction, UserCustomActionDefinition customAction)
        {
            TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Updating user custom action properties.");

            existringAction.Description = customAction.Description;
            existringAction.Group       = customAction.Group;
            existringAction.Location    = customAction.Location;
            existringAction.Name        = customAction.Name;
            existringAction.ScriptBlock = customAction.ScriptBlock;
            existringAction.ScriptSrc   = customAction.ScriptSrc;
            existringAction.Title       = customAction.Title;
            existringAction.Url         = customAction.Url;

            existringAction.Sequence = customAction.Sequence;

            if (!string.IsNullOrEmpty(customAction.CommandUIExtension))
            {
                existringAction.CommandUIExtension = customAction.CommandUIExtension;
            }

            if (!string.IsNullOrEmpty(customAction.RegistrationId))
            {
                existringAction.RegistrationId = customAction.RegistrationId;
            }

            if (!string.IsNullOrEmpty(customAction.RegistrationType))
            {
                // skipping setup for List script
                // System.NotSupportedException: Setting this property is not supported.  A value of List has already been set and cannot be changed.
                if (existringAction.RegistrationType != SPUserCustomActionRegistrationType.List)
                {
                    existringAction.RegistrationType =
                        (SPUserCustomActionRegistrationType)
                        Enum.Parse(typeof(SPUserCustomActionRegistrationType), customAction.RegistrationType, true);
                }
            }

            var permissions = SPBasePermissions.EmptyMask;

            if (customAction.Rights != null && customAction.Rights.Count > 0)
            {
                foreach (var permissionString in customAction.Rights)
                {
                    permissions = permissions | (SPBasePermissions)Enum.Parse(typeof(SPBasePermissions), permissionString);
                }
            }

            existringAction.Rights = permissions;

            ProcessLocalization(existringAction, customAction);
        }
        public void RegisterCustomCoreInScriptLink()
        {
            SPUserCustomAction objSPUserCustomActionScript = null;

            objSPUserCustomActionScript = this.CurrentWeb.UserCustomActions.Add();


            if (!CommonFunctions.IsExistsCustomAction("CustomCore.Js", "ScriptLink", String.Empty, this.CurrentWeb))
            {
                objSPUserCustomActionScript.Location  = "ScriptLink";
                objSPUserCustomActionScript.Name      = "CustomCore.Js";
                objSPUserCustomActionScript.ScriptSrc = "/_layouts/SampleProject/JS/CustomCore.js";
                this.CurrentWeb.AllowUnsafeUpdates    = true;
                objSPUserCustomActionScript.Update();
            }
        }
コード例 #8
0
        private void AddCustomAction(SPList spList)
        {
            string lableText         = "Multi download as ZIP";
            string urlToDownloadPage = SPContext.Current.Web.Url + "/_layouts/SPMultiZipDownload/SPMultiZipDownload.aspx?listId={SelectedListId}&amp;itemId={SelectedItemId}";

            try
            {
                SPUserCustomAction customAction = spList.UserCustomActions.Add();
                customAction.Title              = Const.DownloadCustomActionTitle;
                customAction.Location           = "CommandUI.Ribbon";
                customAction.Group              = "SPMultiZipDownloadActionGroup";
                customAction.Rights             = SPBasePermissions.ViewListItems;
                customAction.CommandUIExtension =
                    "<CommandUIExtension xmlns='http://schemas.microsoft.com/sharepoint/'>" +
                    "<CommandUIDefinitions>" +
                    "<CommandUIDefinition Location='Ribbon.Documents.Copies.Controls._children'>" +
                    "<Button Id='SPMultiZipDownloadButton' Command='SPMultiZipDownload.Button' " +
                    "Image32by32='/_layouts/15/images/SPMultiZipDownload/SPMultiZipDownload_32x32.png' " +
                    "Image16by16='/_layouts/15/images/SPMultiZipDownload/SPMultiZipDownload_16x16.png' " +
                    "TemplateAlias='o1' " +
                    "LabelText='" + lableText + "'/>" +
                    "</CommandUIDefinition>" +
                    "</CommandUIDefinitions>" +
                    "<CommandUIHandlers>" +
                    "<CommandUIHandler " +
                    "Command='SPMultiZipDownload.Button' " +
                    "CommandAction=\"javascript:window.open('" + urlToDownloadPage + "','_self');\" " +
                    @"EnabledScript='javascript:var EnableDisable = function() {
                             this.clientContext = SP.ClientContext.get_current();
                             this.selectedItems = SP.ListOperation.Selection.getSelectedItems(this.clientContext);
                             var ci = CountDictionary(selectedItems);
                             return (ci > 0);
                           };
                           EnableDisable();' />" +
                    "</CommandUIHandlers>" +
                    "</CommandUIExtension>";
                customAction.Update();
            }
            catch (Exception ex)
            {
                WriteExToLog(ex);
            }
        }
コード例 #9
0
 public static string GetRegistrationType(this SPUserCustomAction action)
 {
     return(action.RegistrationType.ToString());
 }
コード例 #10
0
        private void MapCustomAction(SPUserCustomAction existringAction, UserCustomActionDefinition customAction)
        {
            TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Updating user custom action properties.");

            existringAction.Description = customAction.Description;
            existringAction.Group = customAction.Group;
            existringAction.Location = customAction.Location;
            existringAction.Name = customAction.Name;
            existringAction.ScriptBlock = customAction.ScriptBlock;
            existringAction.ScriptSrc = customAction.ScriptSrc;
            existringAction.Title = customAction.Title;
            existringAction.Url = customAction.Url;

            existringAction.Sequence = customAction.Sequence;

            if (!string.IsNullOrEmpty(customAction.CommandUIExtension))
                existringAction.CommandUIExtension = customAction.CommandUIExtension;

            if (!string.IsNullOrEmpty(customAction.RegistrationId))
                existringAction.RegistrationId = customAction.RegistrationId;

            if (!string.IsNullOrEmpty(customAction.RegistrationType))
            {
                // skipping setup for List script 
                // System.NotSupportedException: Setting this property is not supported.  A value of List has already been set and cannot be changed.
                if (existringAction.RegistrationType != SPUserCustomActionRegistrationType.List)
                {
                    existringAction.RegistrationType =
                        (SPUserCustomActionRegistrationType)
                            Enum.Parse(typeof(SPUserCustomActionRegistrationType), customAction.RegistrationType, true);
                }
            }

            var permissions = SPBasePermissions.EmptyMask;

            if (customAction.Rights != null && customAction.Rights.Count > 0)
            {
                foreach (var permissionString in customAction.Rights)
                    permissions = permissions | (SPBasePermissions)Enum.Parse(typeof(SPBasePermissions), permissionString);
            }

            existringAction.Rights = permissions;
        }
コード例 #11
0
        protected virtual void ProcessLocalization(SPUserCustomAction obj, UserCustomActionDefinition definition)
        {
            if (definition.TitleResource.Any())
            {
                foreach (var locValue in definition.TitleResource)
                    LocalizationService.ProcessUserResource(obj, obj.TitleResource, locValue);
            }

            if (definition.DescriptionResource.Any())
            {
                foreach (var locValue in definition.DescriptionResource)
                    LocalizationService.ProcessUserResource(obj, obj.DescriptionResource, locValue);
            }

            if (definition.CommandUIExtensionResource.Any())
            {
                foreach (var locValue in definition.CommandUIExtensionResource)
                    LocalizationService.ProcessUserResource(obj, obj.CommandUIExtensionResource, locValue);
            }
        }
コード例 #12
0
        private void MapCustomAction(SPUserCustomAction existringAction, UserCustomActionDefinition customAction)
        {
            TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Updating user custom action properties.");

            existringAction.Group       = customAction.Group;
            existringAction.Location    = customAction.Location;
            existringAction.Name        = customAction.Name;
            existringAction.ScriptBlock = customAction.ScriptBlock;
            existringAction.ScriptSrc   = customAction.ScriptSrc;

            // fallback for old models
            // fill out Title/Description with Name if NULLs
            // that needs for SP2016 to work well with translation exports

            // UserCustomAction without Title/Description breaks Translation Export #937
            // https://github.com/SubPointSolutions/spmeta2/issues/937

            if (!string.IsNullOrEmpty(customAction.Title))
            {
                existringAction.Title = customAction.Title;
            }
            else
            {
                existringAction.Title = customAction.Name;
            }

            if (!string.IsNullOrEmpty(customAction.Description))
            {
                existringAction.Description = customAction.Description;
            }
            else
            {
                existringAction.Description = customAction.Name;
            }

            existringAction.Url = customAction.Url;

            existringAction.Sequence = customAction.Sequence;

            if (!string.IsNullOrEmpty(customAction.CommandUIExtension))
            {
                existringAction.CommandUIExtension = customAction.CommandUIExtension;
            }

            if (!string.IsNullOrEmpty(customAction.RegistrationId))
            {
                existringAction.RegistrationId = customAction.RegistrationId;
            }

            if (!string.IsNullOrEmpty(customAction.RegistrationType))
            {
                // skipping setup for List script
                // System.NotSupportedException: Setting this property is not supported.  A value of List has already been set and cannot be changed.
                if (existringAction.RegistrationType != SPUserCustomActionRegistrationType.List)
                {
                    existringAction.RegistrationType =
                        (SPUserCustomActionRegistrationType)
                        Enum.Parse(typeof(SPUserCustomActionRegistrationType), customAction.RegistrationType, true);
                }
            }

            var permissions = SPBasePermissions.EmptyMask;

            if (customAction.Rights != null && customAction.Rights.Count > 0)
            {
                foreach (var permissionString in customAction.Rights)
                {
                    permissions = permissions | (SPBasePermissions)Enum.Parse(typeof(SPBasePermissions), permissionString);
                }
            }

            existringAction.Rights = permissions;

            ProcessLocalization(existringAction, customAction);
        }