Is there a way to set permissions to a CEWP in SP2013 on-prem? What i'm trying to do is create a button to a network shared drive, and depending on the permissions set on a SP security group they'll either have access or not. The idea here is trying to not use AD groups to manage the permissions to the shared folder but SharePoint security groups.



I don't think you can security trim the CEWP without editing page layout. Instead try to check current logged in user permission then show/hide links as appropriate Refer here to check user permission


The basic problem here is that you cannot use SharePoint permissions to control access to resources that are outside of SharePoint's control. You can control what SharePoint shows to users when they visit the SharePoint site, so yes, you can control who sees the links when they visit the site, but you are always going to run into the problem of someone passing the link on to someone who shouldn't have it. There is no way to control that.

Regarding how to hide a button rendered through a CEWP though, there are a couple things I can think of.

First, you can wrap your button in a SPSecurityTrimmedControl element, which will hide the control by not rendering it on the server side if you do not have the correct permissions. However, that control by default only checks for certain specific base permission levels (see here and here). You cannot use it out-of-the-box to check for permissions based on groups, however, if you are comfortable coding in C#, you can extend the class to make it work with groups.

The other thought I had, and this is just off the top of my head, completely untried or tested so I have no idea if it would really work, but... how are you using the CEWP? Entering content directly, or linking to file? Potentially, if you put your HTML for rendering the button in an HTML file that you store on the site somewhere, like in Site Pages or Site Assets, you could link that in to your CEWP to get the markup on the page, but then break permission inheritance on the file in the library, and only give permissions to that file to the group that you want to be able to see the link. Then, maybe SharePoint's natural security trimming mechanism would kick in, and not render that file through the CEWP for people who don't have access to the file.

Again, just a thought, completely untested.

And even so, you still have your basic problem, which is that controlling who can see a link to a file share is not the same thing as controlling access to the file share. A user who has access to the link in SP could still send it to someone who does not have access to see the link, and if your permissions on the file share are not set up correctly, they might be able to gain access there.


As a work around, you can use JavaScript code to judge the permission of current user to achieve this.

Here is simple code for your reference.

    <script type="text/javascript">
    function CheckPermissionOnWeb() {
        context = new SP.ClientContext.get_current();

        web = context.get_web();

        var currentUser = web.get_currentUser();


        context.load(web, 'EffectiveBasePermissions');

        context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod), Function.createDelegate(this, this.onFailureMethod));

        function onSuccessMethod(sender, args) {
            if (web.get_effectiveBasePermissions().has(SP.PermissionKind.editListItems)) {
                //User Has Edit Permissions and do something

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.