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..

  • Are you trying to add all users under the domain? You can't pass wild card characters – Amal Hashim May 2 '16 at 14:55
  • @AmalHashim No, I'm trying to add single user only.. All username starts with V***** like ID.. – Arun May 2 '16 at 15:34
  • Can you post code you tried? – Amal Hashim May 2 '16 at 15:35
  • should be @"domain\victor" or "domain\\victor" with two slashes – Mike May 2 '16 at 20:37
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 = "jlennon@thebeatles.com";
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, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.