509.949.2162 jeremy@bondbyte.com

It appears that SPWeb.Users.GetCollection is not bound to its initialized web although SPWeb.Users[username] and SPWeb.Users.GetByEmail(email) are. The unfortunate thing, SPWeb.Users[username] and SPWeb.Users.GetByEmail(email) both throw exceptions if nothing is found.


public static Boolean UserExistsbyEmail(SPWeb web, string email)
{//Throws Exception if account doesn't exsit within the SPWeb
try { SPUser spu = web.Users.GetByEmail(email); }
catch (Exception ex)
{ return false; }
return true;
}

public static Boolean UserExistsbyUserName(SPWeb web, string userName)
{//Throws Exception if account doesn't exist within the SPWeb
try
{ SPUser sp = web.Users[userName]; }
catch (Exception ex)
{ return false; }
return true;
}

public static Boolean UserExistsbyUserNames(SPWeb web, string[] userNames)
{//Returns a collection with a count less than
SPUserCollection spuc = web.Users.GetCollection(userNames);
if (spuc.Count > 0)
{ return true; }
return false;
}

More Info: http://social.msdn.microsoft.com/Forums/en-US/appsforsharepoint/thread/72e0406e-bfb2-4bbf-9979-60396ed5d53c