Archive for August 8th, 2008
Adding a Domain Security Group to a SharePoint Site Programatically
by liquidpooled on Aug.08, 2008, under .NET, Microsoft, Office, Sharepoint Server, Visual Studio 2005, Visual Studio 2008, Windows SharePoint Services
To add a Windows Active Directory Security Group to a SharePoint 2007 or WSS 3.0 site, do the following:
SPContext.GetContext(HttpContext.Current).Web.AllUsers.Add("domain\\Group", "", "", "domain\\Group" );
To add your group to an existing site role (Full Control, Contribute, Read, etc.), use the following:
SPWeb cWeb = SPContext.GetContext(HttpContext.Current).Web; SPUser user = cWeb .AllUsers["domain\\Group"]; SPGroup grouptoadd = cWeb .Groups["Full Control"]; grouptoadd.AddUser(user);