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
    Sep 17 '14 at 6:23
  • user.IsSiteAdmin = true; doesnot work for SP2010 , no error for this.
    – Kb15
    Sep 17 '14 at 6:26
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
    Sep 17 '14 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
    Sep 17 '14 at 6:33
  • Allrite thank you aanchal for your time but this solution is not feasible for me..
    – Kb15
    Sep 17 '14 at 6:46

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.