Role Using Permission in SharePoint 2010 Programmatically Using VS 2010 Via COM


Today, in this article let's play around with one of the interesting and most useful concepts in SharePoint 2010.

Question: What is setting up role based permissions?

In simple terms "It enables creation of a new role and with a defined permission set using the client object model".

Step 1: Open Visual Studio 2010 and create an "ASP.NET Web Forms Application", as in:

 Now two references need to be added to the application; they are:

  • Microsoft.SharePoint.Client

  • Microsoft.SharePoint.Client.Runtime

Step 2: The complete code of webform1.aspx looks like this:


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="RoleUsingPermissionApp._Default" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">

<head id="Head1" runat="server">




    <form id="form1" runat="server">





                    <td colspan="2">

                        <asp:Label ID="Label1" runat="server" Text="Add Role with Permissions in SharePoint 2010 using VS 2010"

                            Font-Bold="true" Font-Size="Large" Font-Names="Verdana" ForeColor="Maroon"></asp:Label>





                        <asp:Label ID="Label2" runat="server" Text="Please Enter Role Name" Font-Size="Large"

                            Font-Names="Verdana" Font-Italic="true"></asp:Label>



                        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>




                    <td colspan="2" align="center">

                        <asp:Button ID="Button1" runat="server" Text="Add Role With Permissions" Font-Names="Verdana"

                            Width="213px" BackColor="Orange" Font-Bold="True" OnClick="Button1_Click" />




                    <td colspan="2" align="center">

                        <asp:Label ID="Label5" runat="server" Font-Bold="true" Font-Names="Verdana" ForeColor="Maroon"></asp:Label>










Step 3: The complete code of webform1.aspx.cs looks like this:


using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using Microsoft.SharePoint.Client;

namespace RoleUsingPermissionApp


    public partial class _Default : System.Web.UI.Page


        protected void Page_Load(object sender, EventArgs e)




        protected void Button1_Click(object sender, EventArgs e)


            if (string.IsNullOrEmpty(TextBox1.Text))


                Label5.Text = "Please Enter Some Values";

                Label5.ForeColor = System.Drawing.Color.Red;




                ClientContext objContext = new ClientContext("http://win-kv3bo1rqqf7:25339/");

                BasePermissions objBasePermission = new BasePermissions();




                RoleDefinitionCreationInformation objCreateInfo = new RoleDefinitionCreationInformation();

                objCreateInfo.BasePermissions = objBasePermission;

                objCreateInfo.Name = TextBox1.Text;



                Label5.Text = "Role with Permission Created Successfully";

                Label5.ForeColor = System.Drawing.Color.Green;

                TextBox1.Text = string.Empty;






Step 4: The output of the application looks like this:




Step 5: Data entering output of the application looks like this:




Step 6: Permission level created output of the application looks like this:






Step 7: Base permissions defined output of the application looks like this:



I hope this article is useful for you.

MVC Corporation
MVC Corporation is consulting and IT services based company.