3

You can add users to the site collection administrators group through
Site Actions ->Site Collection Administrators (and add users)

But how can you do this through code? What is the grpName?

web.EnsureUser(User.LoginName);
web.SiteGroups[grpName].AddUser(@User.LoginName, string.Empty, LookupValue, string.Empty);

3

You need to get the SPUser object for a user in a Site Collection and update the IsSiteAdmin property.

function makeUserSiteCollectionAdmin(SPUser user)
{
    user.IsSiteAdmin = true;
    user.Update();
}
  • Worth noting that the account running the code (i.e. if in a webpart) needs permissions to make this change so a SPSecurity.RunWithElevatedPrivileges block might be required. – Neil Richards Feb 4 '11 at 12:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.