0

I'm facing error while trying to add users into the SharePoint groups using CSOM. When I try to add user by passing user name as "domain\V*****" (all users start with "v" character), it through error as "\v" is hexadecimal value which can't pass.

Also I tried again by adding escape character like @domain\v******, but no luck..

But I tried the code with some test users like "domain\user1" which is working fine.

Any help would be appreciated..

4
  • Are you trying to add all users under the domain? You can't pass wild card characters Commented May 2, 2016 at 14:55
  • @AmalHashim No, I'm trying to add single user only.. All username starts with V***** like ID.. Commented May 2, 2016 at 15:34
  • Can you post code you tried? Commented May 2, 2016 at 15:35
  • should be @"domain\victor" or "domain\\victor" with two slashes Commented May 2, 2016 at 20:37

1 Answer 1

0

I use the code bellow, but like Mike said maybe the key is to provide the string like "domain\user":

UserCreationInformation uci = new UserCreationInformation();
uci.Title = "John Lennon";
uci.Email = "[email protected]";
uci.LoginName = "thebeatles\\jlennon";

Web web = ctx.Web;
GroupCollection groupcoll = web.SiteGroups;
string grouptitle = "My Group";
ctx.Load(web, w => w.SiteGroups);
ctx.Load(groupcoll, grps => grps.Include(g => g.Title).Where(g => g.Title == grouptitle));
ctx.ExecuteQuery();
Group group = null;

User member = web.EnsureUser(uci.Email);
ctx.Load(member, m => m.LoginName, m => m.Title);
ctx.ExecuteQuery();

uci.Title = member.Title;
uci.LoginName = member.LoginName;

if (groupcoll.Count > 0)
{
    group = groupcoll.FirstOrDefault();
    User addeduser = group.Users.Add(uci);
    ctx.ExecuteQuery();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.