To Create group in site collection level use the following command:
string siteUrl = SPContext.Current.Web.Url;
using (SPSite spsite = new SPSite(siteUrl))
{
using (SPWeb web = spsite.OpenWeb())
{
web.SiteGroups.Add("GroupName", web.CurrentUser, web.CurrentUser, "GroupDescription");
web.Update();
}
}
To Create group in site level use the following command:
string siteUrl = SPContext.Current.Web.Url;
using (SPSite spsite = new SPSite(siteUrl))
{
using (SPWeb web = spsite.OpenWeb())
{
web.Groups.Add("GroupName", web.CurrentUser, web.CurrentUser, "GroupDescription");
web.Update();
}
}