tring siteUrl = "http://Site URL";
string strUserName = "DomainName/UserName";
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(siteUrl))
{
using (SPWeb web = site.RootWeb)
{
web.AllowUnsafeUpdates = true;
SPUser spUser = web.EnsureUser(strUserName);
spUser.IsSiteAdmin = true;
spUser.Update();
web.AllowUnsafeUpdates = false;
}
}
});
This will set the user as an admin for the SharePoint site.
string strUserName = "DomainName/UserName";
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(siteUrl))
{
using (SPWeb web = site.RootWeb)
{
web.AllowUnsafeUpdates = true;
SPUser spUser = web.EnsureUser(strUserName);
spUser.IsSiteAdmin = true;
spUser.Update();
web.AllowUnsafeUpdates = false;
}
}
});
This will set the user as an admin for the SharePoint site.
No comments:
Post a Comment