?
Solved

SharePoint 2013 Client Object Model - Adding User to Group

Posted on 2013-02-03
1
Medium Priority
?
1,855 Views
Last Modified: 2013-03-22
I'm using the client object model to add a user to a SharePoint group.  It seems to add them, but the permissions (ability to log into the site) aren't effective for the user.  If I then manually add the user, there are then two instances of the user in the SharePoint group member list, and then the user can log on.  This is my code:

 Sub AddSPUser(ByVal uname As String, ByVal emailaddy As String)
        Dim creds As New Net.NetworkCredential("****", "****", "****")
        Dim siteurl As String = "http://****"
       
        Dim clientContext As New ClientContext(siteurl)
        clientContext.Credentials = creds

        Dim web As Web = clientContext.Web
        Dim user As User
        user = web.EnsureUser("****\" + uname)
        Dim klaMembersGroup As Microsoft.SharePoint.Client.Group = web.SiteGroups.GetById(8)
        Dim userCollection = klaMembersGroup.Users
        
        userCollection.AddUser(user)

        clientContext.Load(user)
        clientContext.Load(klaMembersGroup)
        clientContext.ExecuteQuery()

    End Sub

Open in new window

0
Comment
Question by:ccwestbrook
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 7

Accepted Solution

by:
dhawalseth earned 2000 total points
ID: 38850052
Dear CCWest,

I would recommend you to have a look at the article below:
http://www.learningsharepoint.com/2010/07/27/programatically-create-user-groups-client-object-model-sharepoint-2010/
(it contains code for 2010 and internal links to different tasks required to be completed before adding your user, you have to follow a similar approach for 2013 as well)

http://sharepointquicksolutions.blogspot.in/2012/08/addingremoving-users-tofrom-group.html

The article is in C#, though it comes in handy in guiding about the steps to be taken to add an entry in the user collection.

Enjoy!!!
0

Featured Post

How Blockchain Is Impacting Every Industry

Blockchain expert Alex Tapscott talks to Acronis VP Frank Jablonski about this revolutionary technology and how it's making inroads into other industries and facets of everyday life.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When installing SharePoint 2010 RTM I came across a strange error, I was getting timeouts during the installation. I searched the web and found the best solution to be found here (http://social.msdn.microsoft.com/Forums/en-US/sharepoint2010genera…
The Scenario: Let’s say you have a quote worksheet in Excel that you use to work up sales figures and such for your clients. You utilize SharePoint to manage and keep track of these documents. You would like values from your worksheet to populate Sh…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question