Solved

SharePoint 2013 Client Object Model - Adding User to Group

Posted on 2013-02-03
1
1,807 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 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

We had a requirement to extract data from a SharePoint 2010 Customer List into a CSV file and then place the CSV file into a directory on the network so that the file could be consumed by an AS400 system. I will share in Part 1 how to Extract the Da…
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

707 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