Posted By

blackf0rk on 12/18/09


Tagged

directory user active ActiveDirectory ad sharepoint SPUser


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

jlaws0n


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();
  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  

You need to login to post a comment.