Answered View permissions to a document, list item, library or a list

  • Saturday, April 28, 2012 9:36 PM
     
     

    I want to view the permissions set to a document, list item, library and a list ,I know there is option of Manage permissions for documents and list items where all the users and groups with the permsisions they have are listed,and there is document library permissions where the users and groups with their permissions are listed  but I want to staple a feature to the document or list item such that upon clicking that all the users with their permission should be shown(not groups that is the only difference I want in my custom feature from the one that is already existing), what is the easiest way to do it?

    Thanks,

    D


    D

All Replies

  • Saturday, April 28, 2012 10:56 PM
     
     

    Man please elaborate more I could not understand what do u mean exactly

    thanks


    If the reply was helpful or informative, please remember to mark it as answer or vote as helpful. MCITP SHAREPOINT

  • Sunday, April 29, 2012 6:27 PM
     
     Answered

    Very well. Thats an interesting requirement you got. 

    You can add a  button on ribbon control to a item or to a library. On click of the button, you can open a pop-up where you can display the permissions set for the item or the library.

    to know to add controls on ribbon for a list or to an item follow the link.

    The above link talks about how to add a control on ribbon when item is in edit form. Follow the link for a clear understanding of ribbon controls and how to work with them.

    So once you are able to add a control, on click pass the current item ID and the library name to another page as query string parameters and open the page as a pop-up.

    There you can write the code to read the item and its library to read the permissions. I guess you can handle how to read the permissions. Else let know.

    Thanks.


    Sreeharsha Alagani | MCTS Sharepoint 2010 | Linkedin | Blog

  • Monday, April 30, 2012 1:26 PM
     
     
    @Sreeharsha Alagani, I am actually new to SharePoint object model, could you please direct me to any article that can explain how to read the permissions.

    D

  • Monday, April 30, 2012 1:57 PM
     
      Has Code

    Hey Shrawn here is the code to read the different Role Assignments and their roles on list.

     using (SPSite site = new SPSite("Site Url"))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        SPList list = web.Lists["document Library Name"];
                        
                        foreach (SPRoleAssignment assignment in list.RoleAssignments)
                        {
                            Console.WriteLine(assignment.Member.LoginName);
                            foreach (SPRoleDefinition roleDef in assignment.RoleDefinitionBindings)
                            {
                                Console.Write("--" + roleDef.Name);
                            }
                            Console.WriteLine("");
                        }
                    }
                }


    Sreeharsha Alagani | MCTS Sharepoint 2010 | Linkedin | Blog

  • Monday, April 30, 2012 2:00 PM
     
      Has Code

    And here is the code to read the permissions on a list item.

    using (SPSite site = new SPSite("site url"))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        SPList list = web.Lists["list name"];
                        SPListItem item = list.GetItemById(id);
                        
                        foreach (SPRoleAssignment assignment in item.RoleAssignments)
                        {
                            Console.WriteLine(assignment.Member.LoginName);
                            foreach (SPRoleDefinition roleDef in assignment.RoleDefinitionBindings)
                            {
                                Console.Write("--" + roleDef.Name);
                            }
                            Console.WriteLine("");
                        }
                    }
                }
    Hope that helps.


    Sreeharsha Alagani | MCTS Sharepoint 2010 | Linkedin | Blog