Sunday, 2 December 2012

Programmatically how to create and delete group in SharePoint 2010


Here i want to show how to create and delete groups using visual studio 2010.

Create Group:

            using (SPSite site = new SPSite("http://UKREDDY:6969/"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    web.SiteGroups.Add("TestGroup", web.CurrentUser, web.CurrentUser, "This is Test Group created by Uday.");
                    web.Update();
                }
            }


Delete Group:

Delete newly created group.

            using (SPSite site = new SPSite("http://UKREDDY:6969/"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    web.SiteGroups.Remove("TestGroup");
                    web.Update();
                }
            }



No comments:

Post a Comment