Navigation

Thursday 4 June 2009

How to select an SPUser, even if they haven't already been added

This is a nice quick tip.


You want to get an SPUser object for a user account .. the problem is that you don't know if they have been added to the User Information list yet.

This is especially a problem if an Active Directory Group has been added (and exists in the User Information List) but the actual user hasn't.


Well, there is an easy solution!

SPWeb.EnsureUser(string LoginName)

Pass in a login name to this method. It will validate it, if it isn't already added then it will add it to the User Info List and even returns you the SPUser object that represents the specified user!

Enjoy :)


No comments:

Post a Comment

This blog has been moved to www.martinhatch.com

Note: only a member of this blog may post a comment.