Thursday, 23 June 2011

How to read the Roles and Groups names from a web application- program

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;


namespace consolechk
{
    class Program
    {
        static void Main(string[] args)
        {
            SPSite site1 = new SPSite("http://stage2008:5678/");
            SPWeb web = site1.OpenWeb();
            SPGroupCollection groupcoll = web.Groups;
            foreach (SPGroup group in groupcoll)
             {
                  System.Console.WriteLine(group.Name.ToString());
             }

              Console.WriteLine();
              Console.WriteLine();
              SPRoleCollection rolecoll = web.Roles;
           foreach (SPRole role in rolecoll)
            {
                Console.WriteLine(role.Name.ToString());
            }

            System.Console.ReadLine();
        }
    }
}