Check if Custom Permission level exists or not

I have cretaed a custom permission level.
On feature activation, i need to check if that custom permission level exists or not. How can i do that?
Thanks,
Avni Bhatt

Check if below helps
SPWeb web = SPContext.Current.Web;
// Validate the page request to avoid
// any malicious posts
if (Request.HttpMethod == “POST”)
   SPUtility.ValidateFormDigest();
// Get a reference the roles that are
// bound to the current user and the role
// definition to which we need to verify
// the user against
SPRoleDefinitionBindingCollection usersRoles = web.AllRolesForCurrentUser;
SPRoleDefinitionCollection roleDefinitions = web.RoleDefinitions;
SPRoleDefinition roleDefinition = roleDefinitions["Full Control"];
// Check if the user is in the role. If not
// redirect the user to the access denied page
if (usersRoles.Contains(roleDefinition))
   //Check if post back to run
   //code that initiates the page
   if (IsPostBack != true)
    //Do your stuff here
else
   Response.Redirect(“/_layouts/accessdenied.aspx”);
http://blog.rafelo.com/2008/10/13/programmatically-checking-user-roles-or-permission-levels-in-sharepoint-2007/
http://yoursandmyideas.wordpress.com/2011/10/08/setting-custom-permission-levels-in-sharepoint-programmatically/
Or check if it exist and then delete and recreate it
string[] yourCustomRoles = {"Level1", "Level2"};
using (var web = spSite.OpenWeb())
var roles = web.RoleDefinitions;
foreach(var levelName in yourCustomRoles)
try
roles[levelName];
roles.Delete(levelName);
catch(Exception)
// web has no this role
//Add code here
http://go4answers.webhost4life.com/Example/delete-specific-permissions-108626.aspx

Similar Messages

  • Custom Permission Level Contribute No Delete not working

    I have created a custom permission level that is the same as OOTB Contribute, except it doesn't have the Delete Items nor Delete Versions.
    In my document libraries, I have "require documents to be checked out" set to Yes.
    This is causing some strange behaviour.  When a user (that has my custom Contribute No Delete permission) tries to open a document for editing, they get a message that the document is checked out to their own username, and it won't allow
    them to edit the document.
    What is the best way to remove the "Delete" permission?  We absolutely need this.
    thanks!

    Are you given an option to check it back in via the "back-stage" area? 
    I'd also say that the highest permission grouping wins.  If one group grants a right and another removes it, the additive grouping will win out.  As well as checking the inheritance, it's ideal to remove permissions that might grant this.
    Steven Andrews
    SharePoint Business Analyst: LiveNation Entertainment
    Blog: baron72.wordpress.com
    Twitter: Follow @backpackerd00d
    My Wiki Articles:
    CodePlex Corner Series
    Please remember to mark your question as "answered" if this solves (or helps) your problem.

  • Custom permission levels don't work

    I have created a custom permission level group called custom contribute. The group permission seems to work fine and smoothly one day. The next day that it seems that users of the group can access the site but they cannot do anything else on the site without
    receiving the tell us why you need access message.
    The users in the group are accessing SharePoint from all over the world. Is there something that I can check within the settings  to see why they have access one day and the next they don't? Or is SharePoint setup this way?
    I have full control of the site and nothing changes from day to day. Any help or suggestions on this would be greatly appreciated.

    Hi kedge11,
    Please check permissions for the users with this custom permission level from problematic SharePoint site, verify if they still have the expected custom contribute permissions.
    Also test if this issue could be reproduced, if not, please re-create another same custom permissions for these users again.
    If issue still persists, please check ULS log when this error occurs, it should provide some useful information for helping solve issue.
    Thanks
    Daniel Yang
    TechNet Community Support

  • How to check the given path is existing or not using sp_cmdshell

    Hi All,
       I am passing one path to the stored procedure, before executing code i want to check whether the path is given existing or not .
    By using sp_cmdshell we can know whether files are there are not but in case of my scenario i want to know the directory(folder) is existing or not because the source folder may be blank so it will not get the files there so stored procedure returning the
     File Not found as output.
    following is the code i am trying to retrieve this please suggest any other way to solve it.
    Create table #tableExists  (isValid varchar(255))
    Declare @path varchar(255)='DIR "C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA "/B'
    INSERT INTO #tableExists 
    EXEC xp_cmdshell @path
    select * from #tableExists
    Regards,
    Niraj Sevalkar

    You can try the other two undocumented extended stored procedures as well:
    --EXEC master.dbo.xp_subdirs @pathName
    EXEC Master.dbo.xp_fileexist @pathName
    EXEC Master.dbo.xp_DirTree @pathName,1

  • [req] how to check whether given oracle table exist or not + C#

    Hi,
    All.
    Actually i m creating a program using C# which connects to the database (oracle) and checks for the given table "OPC_GROUP". if the table doesnt exists then it creates the table else it updates all field with provided values
    code
    cmd.CommandText = "SELECT tname from tab where tname = 'OPC_GROUP'";
    cmd.CommandType = CommandType.Text;
    int length = cmd.ExecuteNonQuery();
    if (cmd.ExecuteNonQuery() >0)
    MessageBox.Show("Table does exist");
    else
    MessageBox.Show("Table doesnt exist");
    But this code return "TABLE DOESNT EXIST" though table is already created
    What i m doing wrong???
    Please help..........
    Thnx in advance

    Try this..
    cmd.CommandText = "SELECT count(*) from tab where tname = 'OPC_GROUP'";
    cmd.CommandType = CommandType.Text;
    string strnum = cmd.ExecuteScalar().ToString();
    if (strnum!="0")
    MessageBox.Show("Table does exist");
    else
    MessageBox.Show("Table doesnt exist");
    Hope it helps,
    Greg

  • How to check if a file already exists or not

    javax.swing.filechooser.FileFilter filter = new FileNameExtensionFilter("CSV Files","csv");
                   final JFileChooser fileSelect = new JFileChooser();
                   fileSelect.addChoosableFileFilter(filter);
                   int action = fileSelect.showSaveDialog(JFrame)
                   try{
                        if (action == JFileChooser.CANCEL_OPTION)
                             return;
                        else if (action == JFileChooser.APPROVE_OPTION)
                             SwingUtilities.invokeLater(new Runnable()
                                  public void run()
                                       file = fileSelect.getSelectedFile();
                                       JOptionPane.showMessageDialog(null,file);
                                       if (!file.exists())
                                            JOptionPane.showMessageDialog(null,file.isDirectory());
                                       //fetches the file name from the file name filed in the GUI
                                       final String fileName = ((BasicFileChooserUI)fileSelect.getUI()).getFileName();
                                       if(!fileName.endsWith(".csv"))
                                            //appends the file type to the fetched filename
                                            ((BasicFileChooserUI)fileSelect.getUI()).setFileName(fileName + ".csv");
                                       final String newFileName = ((BasicFileChooserUI)fileSelect.getUI()).getFileName();
                                       //replace the oldfile with filename.csv
                                       String csvFile = file.getPath().replace(file.getPath().substring(file.getPath().lastIndexOf('\\') + 1,file.getPath().length()),"");
                                       file = new File(csvFile.concat(newFileName));
                                       if(file.exists())
                                            JOptionPane.showMessageDialog(null,file);
                                            int response = JOptionPane.showConfirmDialog (null,
                                                      "Overwrite existing file?","Confirm Overwrite",
                                                      JOptionPane.OK_CANCEL_OPTION,
                                                      JOptionPane.QUESTION_MESSAGE);
                                            if (response == JOptionPane.CANCEL_OPTION)
                                                 return;
                                            else
                                                 try
                                                      writeToFile();
                                                 catch (IOException e)
                                                      e.printStackTrace();
                                       else
                                            try
                                                 writeToFile();
                                            catch (IOException e)
                                                 e.printStackTrace();
                   catch(Exception e)
                        e.printStackTrace();
                   }

    Thank u very much
    I got the solution for it
    if(ae.getActionCommand().equals("Export"))
                   data= new Vector();
                   data.addAll(tabData);
                   javax.swing.filechooser.FileFilter filter = new FileNameExtensionFilter("CSV Files(*.csv)","csv");
                   final JFileChooser fileSelect = new JFileChooser();
                   fileSelect.addChoosableFileFilter(filter);
                   int action = fileSelect.showSaveDialog(MainFrame.getMainFrame());
                   try{
                        if (action == JFileChooser.CANCEL_OPTION)
                             return;
                        else if (action == JFileChooser.APPROVE_OPTION)
                             SwingUtilities.invokeLater(new Runnable()
                                  public void run()
                                       file = fileSelect.getSelectedFile();
                                       //fetches the file name from the file name filed in the GUI
                                       final String fileName = ((BasicFileChooserUI)fileSelect.getUI()).getFileName();
                                       if(!fileName.endsWith(".csv"))
                                            //appends the file type to the fetched filename
                                            ((BasicFileChooserUI)fileSelect.getUI()).setFileName(fileName + ".csv");
                                       final String newFileName = ((BasicFileChooserUI)fileSelect.getUI()).getFileName();
                                       //replace the oldfile with filename.csv
                                       String csvFile = file.getPath().replace(file.getPath().substring(file.getPath().lastIndexOf('\\') + 1,file.getPath().length()),"");
                                       JOptionPane.showMessageDialog(null,csvFile);
                                       if (csvFile.endsWith("\\" + "\\"))
                                            csvFile = csvFile.concat(fileName.concat("\\"));
                                       file = new File(csvFile.concat(newFileName));
                                       if(file.exists())
                                            int response = JOptionPane.showConfirmDialog (null,
                                                      "Overwrite existing file?","Confirm Overwrite",
                                                      JOptionPane.OK_CANCEL_OPTION,
                                                      JOptionPane.QUESTION_MESSAGE);
                                            if (response == JOptionPane.CANCEL_OPTION)
                                                 return;
                                            else
                                                 try
                                                      writeToFile();
                                                 catch (IOException e)
                                                      e.printStackTrace();
                                       else
                                            try
                                                 writeToFile();
                                            catch (IOException e)
                                                 e.printStackTrace();
                   catch(Exception e)
                        e.printStackTrace();
    Message was edited by:
    vijaysforum

  • 'Send an email invitation' & 'Select a permission level' options are not visible when clicking "Show Options"

    We're using a modified master page, which is 99% identical to the Seattle.master file. However, we are facing some JavaScript issues. This one in particular is affecting the event listener for the "Show Options" link while adding a new user.
    If anyone knows what SharePoint OOTB JavaScript functions and/or file is directly linked to this event handler, please share. Thanks in advance!

    Hi,
    Per my knowledge, the "Show More" link use the function as below:
    onclick="EnsureScriptParams('foldhyperlink.js', 'ToggleFoldText', '4f7670f8b24440de93663a84177ebd88', 'ctl00_PlaceHolderMain_ctl03__moreDetailsLink', 'Hide options', 'Show options');ShowHideMoreOptions();return false;">
    Thanks,
    Linda
    Linda Li
    TechNet Community Support

  • Regarding creating SharePoint custom permissions not permission level

    Hi All,
    i want to create or manage custom permissions under permission level.
    like
    for list items Manage Lists and add items etc.
    Thanks in advance.
    Kindly suggest me some suggestion
    Varsha Patil

    Use SPSecurityTrimmedControl control to for specific users or group. But still SPSecurityTrimmedControl will not work for full control so you also need to customize permission for full controls users.
    First go to permission level page and modify the permission for full control. uncheck the permission for whom you don't want to show this control (refer below link to know about base permission)
    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spbasepermissions.aspx
    Then do the same for custom permission level. and now assign this custom permission to group. Later use  SPSecurityTrimmedControl in above menu and then hide/show control for users.
    http://social.technet.microsoft.com/Forums/en-US/9496525a-3f8f-47e3-a3c0-73d9a1670b0d/how-to-make-the-site-actions-menu-invisible-to-certain-users?forum=sharepointgenerallegacy
    http://social.msdn.microsoft.com/Forums/en-US/0dba2a60-204d-44d9-968f-84cd41f52e2d/how-to-hide-site-actions-menu-for-user-group?forum=sharepointcustomizationlegacy
    Hemendra:Yesterday is just a memory,Tomorrow we may never see
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

  • Lock a custom site permission level

    Hello,
    In SharePoint 2013 I have created a custom permission level called Site Owner.  It was modeled off the Full Control level and basically I just wanted to remove the "Create Subsites" permission.
    Now our site owners should still be able to modify/add/edt permissions to the site - but I don't want them to be able to create their own custom permission levels or to modify existing ones (like the one I created so that they could then create subsites).
    I've tried to remove the Manage Permissions and the Enumerate Permissions but then they can't do any permission changes.
    Is it possible have a user be able to edit site/list/etc permissions but not edit Site permissions levels?
    Thanks!
    Ruby

    Hi  Ruby,
    According to your description, my understanding is that you want to restrict your users editing Site permissions levels  but remain them editing site/list/etc permissions .
    As far as I know, it is infeasible by OOTB . For a workaround, you can remove the “Create Subsites” permission in your Web Application:
    Go to your Central Administration -> Application Management -> Manage web applications.
    Select your Web Application, click  “User Permissions”.
    Uncheck “Create Subsites” Permission and Save.
    Thanks,
    Eric
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support,
    contact [email protected]
    Eric Tao
    TechNet Community Support

  • Is there any std. BAPI to check both user name and password exist or not

    Hi frnds,
    I am looking for a std. bapi to check both username and password exist or not..
    i found one bapi bapi_user_existence_check. but it checks only username...

    I don't think that you will have access to the passwords that are stored in the system.
    If so, you could read every user's password and logon to the system.
    I guess that they're encrypted and stored on the database.
    Why do you need to check for the password. Isn't the username sufficient?

  • Permission Level

    I have custom permission level, however I need to break the permission from the parent site and set a custom permission for this sub site. Please advice detail instructions on how to do this without breaking the parent site permission level.
    Renee W

    Hi
    check this similar post
    https://social.msdn.microsoft.com/Forums/ro-RO/83bf0883-986e-4881-8470-9e012624bc05/custom-permission-levels-subsite-access-global-navigation-and-webpart-permissions-configuration?forum=sharepointadminlegacy
    Romeo Donca, Orange Romania (MCSE, MCITP, CCNA) Please Mark As Answer if my post solves your problem or Vote As Helpful if the post has been helpful for you.

  • Stored Procedure for custom permission check

    Hi,
    I have created 2 UDTs for Master Data and Master Rows, and generated a UDO form for this.
    Only few users can add master data, but all users should be able to update fields in the rows for existing master records (but not the fields in the header).
    For this, I can probably add a custom permission UDF in User Master.
    But how can I code the Stored Procedure based on this UDF in the User Master, and whether rows are modified for existing records?
    Thanks.

    John......
    Try this.....
    IF (@object_type = '140' And (Select ObjType From OPDF
           Where DocEntry = @list_of_cols_val_tab_del)='46'
    AND @transaction_type IN ('A'))
    BEGIN
    if exists(select t0.DocEntry from OPDF T0 inner join PDF4 T1 on
    T0.DocNum = T1.DocNum where t1.ObjType ='46' AND (T0.Series = '15' AND T1.OcrCode != 'U-1')
    and T0.DocEntry = @list_of_cols_val_tab_del)
    begin
    select @error = 1,
    @error_message = 'Check Unit'
    end
    End
    Above SP will only work when your Series Code is 15 and OcrCode is not equal to 'U-1'....
    Please confirm........
    And Object type for Payment Draft 140 is right.....
    Regards,
    Rahul

  • IViews are not updated in customized top level navigation

    Hi experts,
    I am working on External Facing Portal. I developed customized top level navigation. The problem is that the content area of External Facing portal is not refreshed. Although, i can see different navigationURLs but content area iView remains same. For testing purpose, i assigned role (which i created for anonymous access) to a new portal user. All pages/ivews/ for that role are working fine and content area is also updated when i click on different navigation. Remember that is standard portal not anonymous. It means through myserver:50100/irj/protal?NavigationTarget=navurl://cb0c473832f39033f88904647de63252 all navigation is working fine including content area but when i access External Facing Portal through  myserver:50100/irj/protal/anonymous?NavigationTarget=navurl://cb0c473832f39033f88904647de63252 navigationURLs is updated but the content area remains same. Content area contains 1 page and page itself contains 1 iVew. I assigned that light page to Light Framework page.
    Do i need to implement navigation connectors for that issue or i miss something?
    waiting for your response.
    regards
    Abbas

    Have you tried disabling the iView caching (check the iView and page properties). Your browser and proxy server (as you mention it is external facing) may also be caching the content, hence the reason when you use your user ID and the Java restart occurs everything is reset correctly.
    I know when doing Visual Composer developments that SAP EP caches the Function Module interfaces and that in the development environment I needed to change parameters in Visual Admin for the VC component lifetime to handle these. It could well be that you are referencing components that have lifetime keep alive set for them in the environment too. Refer to the API / SDK documentation if you suspect this could be the case for you too.
    What exactly is the iView in the content area doing? Is it just a transactional iView or is it a custom iview?
    If you can perhaps try putting on an http trace or monitor the NWA logs to determine if any issues exist. You Java VM may also require some more fine tuning in the external facing scenario - the GC may not be collecting items efficiently.

  • Share Button not show Permission Level

    Hi,
    We are facing a weird problem in our farm, we have until CU July 2014 versión with an authentication with ADFS2.0.
    In all Site Collections we have breaked the inherited permissions and we gave permissions directly to the SC or by AD Groups, until here, there is no problem
    But recently, we have discovered that the share button in Site collection does not work properly, in some SC it only shows the following:
    But in other sites we have done the same, and it shows correctly the Level permissions of the SC. I have checked that is not a problem with the Custom Master we have deployed, since I have created this SC with the original Seattle Master Page.
    Anyone knows what is happening??
    Thanks

    Hi again,
    With the share button, we have detected the following:
    In SharePoint 2013 Foundation, the share button points to
    http://urlsc/_layouts/15/aclinv.aspx?forsharing=1&lsDlg=1 and it shows both, SharePoint groups and permission levels (Full Control, read, design...) but in SharePoint 2013 Standard and Enterprise, this same share button points to
    http://urlsc/_layouts/15/aclinv.aspx?forsharing=0&lsDlg=1 where only displays SharePoint Groups.
    Anyone knows why this difference? It is a bug? What is the behaviour?
    Thanks

  • Getting error while opening a saved for later notification: The selected action is not available. The cause may be related to security. Contact your system administrator to verify your permission level for this action.

    Hi All,
    While opening a saved for later notification, we are getting "The selected action is not available. The cause may be related to security. Contact your system administrator to verify your permission level for this action". error.
    This is a custom notification.
    Please help.
    Thanks
    Raghava

    HI All,
    Please help on this issue.
    Thanks
    Raghava

Maybe you are looking for