How to add ACTIVE DOMAIN user to Sharepoint group
Posted
by standley-nguyen
on Stack Overflow
See other posts from Stack Overflow
or by standley-nguyen
Published on 2010-05-24T10:08:45Z
Indexed on
2010/05/24
10:11 UTC
Read the original article
Hit count: 306
sharepoint
Hi all.
I got an exception when executing this snippet code
SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite site = new SPSite(siteUrl.Trim())) { using (SPWeb web = site.OpenWeb()) { try { web.AllowUnsafeUpdates = true; SPUser spUser = web.AllUsers[userName];
if (spUser != null)
{
SPGroup spGroup = web.Groups[groupName];
if (spGroup != null)
spGroup.AddUser(spUser);
}
}
catch (Exception ex)
{
this.TraceData(LogLevel.Error, "Error at function Named [AddUserToSPGroupWidget.AddUserToGroup] . With Error Message: " + ex.ToString());
}
finally
{
web.AllowUnsafeUpdates = false;
}
}
}
});
PLease guide me. Thanks in advance.
© Stack Overflow or respective owner