Skip to main content
added 213 characters in body
Source Link
Ali Jafer
  • 17.8k
  • 1
  • 28
  • 41

or do:

using (SPWeb web = SPContext.Current.Site.RootWeb) 
{
    SPUser user = web.Users["UserLoginName"];
}

get the correct web context if your looking for the root web of a site ;)

or do:

using (SPWeb web = SPContext.Current.Site.RootWeb) 
{
    SPUser user = web.Users["UserLoginName"];
}

get the correct web context if your looking for the root web of a site ;)

Source Link
Ali Jafer
  • 17.8k
  • 1
  • 28
  • 41

just created this console app for you:

        try
        {
            using (SPSite mysite = new SPSite("http://yourwebsite:2010"))
            {

                using (SPWeb web = mysite.OpenWeb())
                {
                    Console.Write("web users");
                    Console.WriteLine();
                    Console.WriteLine();
                    foreach (SPUser user in web.Users)
                    {
                        Console.Write(user.Name);
                        Console.WriteLine();
                    }

                    Console.WriteLine();
                    Console.WriteLine();
                    Console.Write("site collection users");
                    Console.WriteLine();
                    Console.WriteLine();
                    foreach (SPUser user in web.SiteUsers)
                    {
                        Console.Write(user.Name);
                        Console.WriteLine();
                    }
                }

            }
        }
        catch (Exception a)
        {
        }

        Console.Read();

so what you want is web.SiteUsers for site collection and web.Users for webs ;) not web.Site.RootWeb.Users. If you run the code above within a console app you should see the user within the list and if it has a domain tag or not!