Identify Unique Permission of a Web Site

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Text;  
  4. using Microsoft.SharePoint.Client;  
  5. using System.Net;  
  6.   
  7. namespace IdentifyWebPermission  
  8. {  
  9.     class Program  
  10.     {  
  11.         static void Main(string[] args)  
  12.         {  
  13.             //Get Site Url fro user  
  14.             Console.Write("Enter Site URL: ");  
  15.             string strURL = Console.ReadLine();  
  16.               
  17.             //Get Username from user in the format of (Domain/Login ID)  
  18.             Console.Write("Enter UserName (domain/userid): ");  
  19.             string strUserName = Console.ReadLine();  
  20.                           
  21.             Console.Write("Enter your password: ");              
  22.             string pass = getPassword();  
  23.             Console.WriteLine();  
  24.   
  25.             ClientContext ctx = new ClientContext(strURL);  
  26.             ctx.Credentials = new NetworkCredential(strUserName, pass);  
  27.             Web web = ctx.Web;  
  28.             //Parameters to receive response from the server  
  29.             //HasUniqueRoleAssignments property should be passed in Load method to get the value  
  30.             ctx.Load(web, w => w.HasUniqueRoleAssignments, w => w.Title);  
  31.             ctx.ExecuteQuery();  
  32.             Console.WriteLine("Site \""+ web.Title+ "\" has Unique Permission: "+ web.HasUniqueRoleAssignments);  
  33.             Console.Read();  
  34.         }  
  35.   
  36.         private static string getPassword()  
  37.         {  
  38.             ConsoleKeyInfo key;  
  39.             string pass = "";  
  40.             do  
  41.             {  
  42.                 key = Console.ReadKey(true);  
  43.                 // Backspace Should Not Work  
  44.                 if (key.Key != ConsoleKey.Backspace && key.Key != ConsoleKey.Enter)  
  45.                 {  
  46.                     pass += key.KeyChar;  
  47.                     Console.Write("*");  
  48.                 }  
  49.                 else  
  50.                 {  
  51.                     if (key.Key == ConsoleKey.Backspace && pass.Length > 0)  
  52.                     {  
  53.                         pass = pass.Substring(0, (pass.Length - 1));  
  54.                         Console.Write("\b \b");  
  55.                     }  
  56.                 }  
  57.             }  
  58.             // Stops Receving Keys Once Enter is Pressed  
  59.             while (key.Key != ConsoleKey.Enter);  
  60.             return pass;  
  61.         }  
  62.     }  
  63. }