Solved

SharePoint 2013 Client Object Model - Adding User to Group

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
DataTabe not rendering correctly... 2 50
General InfoPath Question - SharePoint 2010/2013 2 71
Sharepoint KB 2 74
sharepoint 2013 calculated column error 5 31
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…
SharePoint Designer 2010 has tools and commands to do everything that can be done with web parts in the browser, and then some – except uploading a web part straight into a page that is edited in SPD. So, can it be done? Scenario For a recent pr…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

772 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