I am writing a program where I want to be able to add/remove user/groups as administrator for a given Site Collection. I am using Client Object Model API for SharePoint 2010. I havent been able to find any API which would allow me to do that. Is this something which is even possible via Client Object Model? If yes how ?
Programatically setting Site Collections Administrators in SharePoint 2010 using Client Object Model
2 Answers
You can't do that with 2010 client object model but it is now possible with 2013.
For promoting a user to Site collection admin we need to:
- Set the
IsSiteAdminproperty to true.
Having said that you can't set the IsSiteAdmin property via 2010 client object model.
However, it is quite possible to do it via:
- Server side object model
- PowerShell
-
This answer more precisely addresses the initial question, so +1Alexey Krasheninnikov– Alexey Krasheninnikov2013-10-22 19:54:43 +00:00Commented Oct 22, 2013 at 19:54
-
I have SP2013 with the v16 API. Whenever I change the IsSiteAdmin property it is not stored.Wout– Wout2014-06-26 11:49:13 +00:00Commented Jun 26, 2014 at 11:49
-
Are you using JSOM or CSOM?Falak Mahmood– Falak Mahmood2014-06-27 00:09:59 +00:00Commented Jun 27, 2014 at 0:09
-
@FalakMahmood Is there a way to do this using REST API or any webservice? I need to add an admin as Site Collection Admin to some tenant users, but the problem is that this admin user is NOT a site user on any of these OneDrive (my site) and I have the access token for this ADMIN user with all permissions.Syed Mauze Rehan– Syed Mauze Rehan2015-03-16 17:53:00 +00:00Commented Mar 16, 2015 at 17:53
EDIT
just looked over the code and your right it doesnt work, I had a deep look at the webservices ootb provided by sharepoint and there is no function to perform the job!! so the next solution would be to make your own webservice that does it for you!
within the webservice add:
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;
}
call that method with Ajax soap call.
to create a webservice follow:
-
Although you add value, the answer is not strictly on topic and misleads. By adding users to groups you don't grant them IsSiteAdmin status.Alexey Krasheninnikov– Alexey Krasheninnikov2013-10-22 19:53:30 +00:00Commented Oct 22, 2013 at 19:53
-
im sorry @AlexeyKrasheninnikov but your missing the op question, "I want to be able to add/remove user/groups as administrator for a given Site Collection." This answer is on topic and is not misleading what so ever the code above removes the user from a selected group using that webservice, tweaking it can also remove user!Ali Jafer– Ali Jafer2013-10-22 23:56:56 +00:00Commented Oct 22, 2013 at 23:56
-
I agree with @AlexeyKrasheninnikov. What you have mentioned is adding a user to a group. I am not sure how this solves my problm of making a user site administratorAshish Jhunjhunwala– Ashish Jhunjhunwala2013-10-23 09:57:51 +00:00Commented Oct 23, 2013 at 9:57
-
1just ammended my solution! sorry for the run around ;)Ali Jafer– Ali Jafer2013-10-23 10:34:35 +00:00Commented Oct 23, 2013 at 10:34
-
1Well, it's actually quite a different answer. You probably shouldn't have removed the initial response completely - now the comments are out of context.Alexey Krasheninnikov– Alexey Krasheninnikov2013-10-30 07:32:39 +00:00Commented Oct 30, 2013 at 7:32