Use of spuser
Spuser is a user class in Sharepoint. When getting the spuser object, you can use spweb. users, spweb. allusers or sprole. users to get a spusercollection, and then get the user in the following two ways.
·Users[String loginname]: gets the user in the collection using the login name;
·Users[Int Index]: obtains the user using the subscript in the set.
You can also use the following method.
· Getbyid (int id): obtains the object of a user using the user ID;
· Getbyemail (string email): obtains the object of a user through the user's email address.
If you only need to obtain the current user, you can also conveniently use the spweb. currentuser attribute.
Use the method in the spusercollection class when adding or deleting a user for a collection.
· Addcollection (spuserinfo [] users): adds a batch of users. spuserinfo is a simple structure, which includes four attributes: email, loginname, name, and notes, for more information about attributes, see attributes of the spuser class;
· Remove (INT index): deletes users in a set by subscript in the set;
· Remove (string loginname): deletes a user using the user's login name;
· Removebyid (int id): Used to delete a user;
· Removecollection (string [] loginnames): deletes a batch of users by using their login names.
Spuser has the following common attributes.
· Email: the user's email address;
· ID: ID (INT type) that uniquely identifies the user on the current site (read-only );
· Isdomaingroup: whether the user is a domain group (read-only );
· Issiteadmin: whether the current user is a website administrator (read-only );
· Loginname: the user's login name (read-only );
· Name: Display name of the user;
· Notes: a brief description of the user;
· Parentweb: the user's website (read-only );
· Roles: Role of the user on the website;
· XML: Description of the user information in XML format (read-only ).
It is worth noting that in the above user information, only loginname is unique (and globally unique) on different websites, users may have different email, display names, and descriptions.
After modifying the attributes of a user, you must call the spuser. Update method to make the modification take effect.