Home > DeveloperSection > Articles > Getting the permission levels from SharePoint 2010 using C#

Getting the permission levels from SharePoint 2010 using C#

Posted by  Rohit Kesharwani
on    December-14-2011 13:34 PM

SharePoint SharePoint 
Ratings:
1 Comment(s)
 6216  View(s)
Rate this:

Getting the permission levels from SharePoint 2010 using C#

In this article I am going to explain how to get all the permission levels in SharePoint 2010 using C#.

Steps involved:

  • Go to Visual Studio 2010.
  • Go to File à New à Project.
  • Select Windows Application and apply the following settings to your project:
    Target Framework: .NET 3.5
    Build output: AnyCpu (or x64)
  • Click Add.

Getting the permission levels from SharePoint 2010 using C#

Getting the permission levels from SharePoint 2010 using C#

Next, we need to add references. Right click the “References” node and choose “Add Reference”.

Getting the permission levels from SharePoint 2010 using C#

·         Choose Browse:

·         Go to the following location: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI.

·         Select Microsoft.SharePoint.dll files:

Add the following code in the Program.cs file:

using System;

using System.Collections.Generic;

using System.Text;

using Microsoft.SharePoint;

 

namespace SampleApplication1

{

    class Program

    {

        static void Main(string[] args)

        {

            using (SPSite site = new SPSite("http://rohit:34143/"))

            {

                using (SPWeb web = site.RootWeb)

                {

                    SPRoleDefinitionCollection roleColl = web.RoleDefinitions;

                    foreach (SPRoleDefinition role in roleColl)

                    {

                        Console.WriteLine(role.Name.ToString());

                    }

                    Console.ReadLine();

                }

            }

        }

    }

}

Output:

Getting the permission levels from SharePoint 2010 using C#

Thanks for reading this article. I think this will help you a lot.


Getting the permission levels from SharePoint 2010 using C#

By Arun Singh on   2 years ago
Hi Rohit,
This is one of the best answer so far, I  have read online. Just useful information. Very well presented. Thanks for sharing with us.















Recent Activities


Barbara Jones added new Question What is ANR?   3 days ago

Kamlakar Singh added new Blog Convert Text Document to PDF File   16 days ago

Kamlakar Singh added new Article Introduction to Backbone.js   16 days ago

Don't want to miss updates? Please click the below button!