0

I searched for this but in vain.

Used this below code for SharePoint 2013 and works fine, but now need to develop for SharePoint 2010.

 Web web = _ctx.Web;
 User user = web.EnsureUser(userName);                        
 user.IsSiteAdmin = true; 
 user.Update();
 _ctx.ExecuteQuery();

Any other way by which I can add user to site collection administrator in SP2010 ?

Please help me out to solve this.

2
  • Are you getting any error with this code in 2010?
    – Aanchal
    Commented Sep 17, 2014 at 6:23
  • user.IsSiteAdmin = true; doesnot work for SP2010 , no error for this.
    – Kb15
    Commented Sep 17, 2014 at 6:26

1 Answer 1

1

You can't do that with 2010 client object model but it is now possible with 2013. You can use Server object model or Powershell to add users to site collection administrator group.

Another option would be create a custom webservice to add users to that group.

3
  • I am developing WCF service, so Server object model or PowerShell can't be an option and as u said add users to that group ? is Site Collection Administrator considered as any group ? Please guide me to that groupId
    – Kb15
    Commented Sep 17, 2014 at 6:30
  • You need to host that service in sharepoint and use following code. public bool SetSiteCollAdmin(string siteURL,string userAccount) { using(SPSite site=new SPSite(siteURL)) { using (SPWeb web = site.RootWeb) { SPUser user = web.EnsureUser(userAccount); user.IsSiteAdmin = true; user.Update(); return true; } } return false; }
    – Aanchal
    Commented Sep 17, 2014 at 6:33
  • Allrite thank you aanchal for your time but this solution is not feasible for me..
    – Kb15
    Commented Sep 17, 2014 at 6:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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