Adding a Domain Security Group to a SharePoint Site Programatically

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);
Bookmark and Share
Leave a comment

0 Comments.

Leave a Reply


[ Ctrl + Enter ]

Performance Optimization WordPress Plugins by W3 EDGE