To assign the user to group in MOSS 2007
The following code will add the user to site and to specified group.
private void AddUser(string strSite,string webGroup)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
utilizând (SPSite site = new SPSite(strSite))
{
utilizând (SPWeb web = site.OpenWeb())
{
Boolean allowUnsafeUpdate = web.AllowUnsafeUpdates;
încercaţi
{
web.AllowUnsafeUpdates = true;
web.SiteUsers.Add(loginName, MailId, loginId, “”);
web.Groups[webGroup].AddUser(loginName, MailId, loginId, “”);
}
finally
{
web.AllowUnsafeUpdates = allowUnsafeUpdate;
}
}
}
});
}
Plecare un Reply