Add user to SharePoint


/ Published in: C#
Save to your folder(s)



Copy this code and paste it in your HTML
  1. //get a handle on our sites and web(s)
  2. SPSite Site = new SPSite("<sharepoint url>");
  3. SPWeb Web = Site.OpenWeb();
  4.  
  5. //get a handle on our current users (if any):
  6. SPUserCollection users = Web.AllUsers;
  7.  
  8. //add the new user (see my snippet on getting users from Active Directory, which comes in handy here)
  9. users.Add("<login name>", "<email address>", "<name>", "<notes>");
  10.  
  11. //no need to do an .update()
  12. //you can now return this user as an SPUser:
  13. SPUser newUser = users["<login name>"];

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.