Solved

SharePoint 2013 Client Object Model - Adding User to Group

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SharePoint 2013 Document Library Newsletter View Count 3 68
JavaScript waiting 14 84
SP2010 Parent Child Relationship 3 41
Icons on a page, side-by-side 6 46
For SharePoint sites, particularly public-facing ones, there are times when adding JavaScript, Meta Tags, CSS Styles or other content to the page <head> section is more practical than modifying master pages.  For instance, you could add the jQuery l…
The vision: A MegaMenu for a SharePoint portal home page The mission: Make it easy to maintain. Allow rich content and sub headers as well as standard links. Factor in frequent changes without involving developers or a lengthy Dev/Test/Prod rel…
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 …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

820 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