Solved

SharePoint 2013 Client Object Model - Adding User to Group

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Pimping Sharepoint 2007 without Server-Side Code Part 1 One of my biggest frustrations with Sharepoint 2007 in the corporate world is that while good-intentioned managers lock down the more interesting capabilities of Sharepoint programming in…
Summary In SharePoint 2010 it is easy to create custom color themes to jazz up a site. Theme colors can also be created in PowerPoint 2010 with a few clicks. But how do the chosen colors actually look in the SharePoint site? The attached PowerPoint…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

760 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now