Monday, December 8, 2008

User not found

Error:
Code web.User[@"domain\username"] throws 'user not found' error

Reason:
SPWeb supports User and SiteUsers collection and they differ in following way.

-->SPWeb.Users

This property returns collection of user objects that are explicitly assigned permissions.

-->SPWeb.SiteUsers

This property returns collection of user objects that belong to site collection.

So use the following to read users which are not explicitly added to a 'web'.
Code:

SPUser user = SPContext.Current.Web.SiteUsers[@"domain\username"];
or
Add the user to the web explicitly :
Site Settings > Permissions > Add User
Article:
http://weblogs.asp.net/bsimser/archive/2006/03/13/440169.aspx

0 comments: