If this sounds confusing it's because I'm al little confused on it myself. Basically I have an application (originally written by someone else but never finished) that needs to perform various actions on spuser objects. The catch is that the input being used to find the user can be any of several types of identification. The method requiring this may have user information in the form of user Id, login name, email address, account name, etc. The method needs to detect what kind of information it is and use an appropriate means for retrieving the user account.
My first (and only) idea was to use exception handling to take the value and "brute force" it by trying a series of gets until one of them finally sticks. As in,
try
{
SPUserCollection myUserCollection = myWeb.Users;
SPUser myUser = myUserCollection.GetByEmail(value);
}
catch
{
try
{
SPUserCollection myUserCollection = myWeb.Users;
SPUser myUser = myUserCollection.GetById(value);
}
catch
{
...and so on
Of course this is horribly messy and I"m not even sure it will work. Is there a better way? I really don't want to scrap the whole thing and start over because it would take a huge amount of time and experience that I don't have yet, so I really want to hack something together that will do the job for the moment until I know how to write something better.
Thanks in advance for any help you can provide!