none
check user access in the site using object model in sharepoint 2010

    Question

  • I want to Get User Permissions(whether view/Contribute) for a particular site.


    sree


    • Edited by sree_23 Monday, April 16, 2012 7:47 AM
    Monday, April 16, 2012 7:29 AM

Answers

  • Hi,

    Instead of using VS, you can use sharepoint manager codeplex tool to view the sharepoint permission manager codeplex tool.

    http://permissionsmanager.codeplex.com/

    Let us know if it is helpful


    Cheers, Hemendra-MCTS "Yesterday is just a memory,Tomorrow we may never see"

    • Marked as answer by Shimin Huang Friday, April 27, 2012 8:22 AM
    Monday, April 16, 2012 8:14 AM
    Moderator
  • Hello

    For this, you need to check the role of the current user with something like this

    SPWeb web = SPContext.Current.Web;
    SPRoleAssignment assignment = web.RoleAssignments.GetAssignmentByPrincipal((SPPrincipal) web.CurrentUser);
    
    
    foreach (SPRoleDefinition role in assignment.RoleDefinitionBindings)
    
    {
    
    //Check the role you are looking for and do your stuff
    
    
    }


    Hope this help


    Best regards, Christopher.
    Blog | Mail

    • Marked as answer by Shimin Huang Friday, April 27, 2012 8:21 AM
    Monday, April 16, 2012 8:49 AM
    Answerer
  • You can use the oob SharePoint User Group web service to retrieve this data:

    http://YourSite/_vti_bin/usergroup.asmx

    List<string> userGorups = new List<string();
    using (SharePoint_UserGroup.UserGroup proxy = new SharePoint_UserGroup.UserGroup())
                    {
                        proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
                        proxy.Url = System.IO.Path.Combine(siteUrl, "_vti_bin/usergroup.asmx").Replace("\\", "/");
                        System.Xml.XmlNode ndGroups = proxy.GetGroupCollectionFromUser(userId);
                        foreach (System.Xml.XmlNode xmlGroup in ndGroups.ChildNodes[0].ChildNodes)
                        {
                          string groupName =sharepointGroup, xmlGroup.Attributes["Name"].Value;
                          userGorups.Add(groupName);
                        }
                    }
                       


    K. http://www.sharepointwithattitude.com

    • Marked as answer by Shimin Huang Friday, April 27, 2012 8:21 AM
    Monday, April 16, 2012 6:28 PM

All replies

  • Hi,

    Instead of using VS, you can use sharepoint manager codeplex tool to view the sharepoint permission manager codeplex tool.

    http://permissionsmanager.codeplex.com/

    Let us know if it is helpful


    Cheers, Hemendra-MCTS "Yesterday is just a memory,Tomorrow we may never see"

    • Marked as answer by Shimin Huang Friday, April 27, 2012 8:22 AM
    Monday, April 16, 2012 8:14 AM
    Moderator
  • Hello

    For this, you need to check the role of the current user with something like this

    SPWeb web = SPContext.Current.Web;
    SPRoleAssignment assignment = web.RoleAssignments.GetAssignmentByPrincipal((SPPrincipal) web.CurrentUser);
    
    
    foreach (SPRoleDefinition role in assignment.RoleDefinitionBindings)
    
    {
    
    //Check the role you are looking for and do your stuff
    
    
    }


    Hope this help


    Best regards, Christopher.
    Blog | Mail

    • Marked as answer by Shimin Huang Friday, April 27, 2012 8:21 AM
    Monday, April 16, 2012 8:49 AM
    Answerer
  • You can use the oob SharePoint User Group web service to retrieve this data:

    http://YourSite/_vti_bin/usergroup.asmx

    List<string> userGorups = new List<string();
    using (SharePoint_UserGroup.UserGroup proxy = new SharePoint_UserGroup.UserGroup())
                    {
                        proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
                        proxy.Url = System.IO.Path.Combine(siteUrl, "_vti_bin/usergroup.asmx").Replace("\\", "/");
                        System.Xml.XmlNode ndGroups = proxy.GetGroupCollectionFromUser(userId);
                        foreach (System.Xml.XmlNode xmlGroup in ndGroups.ChildNodes[0].ChildNodes)
                        {
                          string groupName =sharepointGroup, xmlGroup.Attributes["Name"].Value;
                          userGorups.Add(groupName);
                        }
                    }
                       


    K. http://www.sharepointwithattitude.com

    • Marked as answer by Shimin Huang Friday, April 27, 2012 8:21 AM
    Monday, April 16, 2012 6:28 PM
  • check this blog which talks about getting base permissions for current user -

    http://spdailytips.blogspot.in/2011/09/check-current-user-permission.html


    ArchaHim

    Tuesday, April 17, 2012 6:22 AM
  • Hi!

    In what context are you searching for the user credentials? Is it in a webpart, page, timer job, code behind?


    Sebastian | MCTS | MCPD | MCC

    Tuesday, April 17, 2012 7:51 AM