Posted By

blackf0rk on 12/18/09


directory user active ActiveDirectory ad sharepoint SPUser

Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


Add user to SharePoint

 / Published in: C#

  1. //get a handle on our sites and web(s)
  2. SPSite Site = new SPSite("<sharepoint url>");
  3. SPWeb Web = Site.OpenWeb();
  5. //get a handle on our current users (if any):
  6. SPUserCollection users = Web.AllUsers;
  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>");
  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  

You need to login to post a comment.