1

How to bind all the users of Sharepoint(office 365) except system users like :

"System Account",

"NT AUTHORITY\authenticated users",

"_SPOCacheFull",

"YLO001_spocrwl_142_11094".

I want only custom added users like :

user1@site12345.onmicrosoft.com

user2@site12345.onmicrosoft.com

Currently I am binding all users like this:


using (SPSite spSite = SPContext.Current.Site)
{
    using (SPWeb web = spSite.OpenWeb())
    {
       web.AllowUnsafeUpdates = true;

       SPUserCollection users = web.AllUsers;
       foreach (SPUser user in users)
       {
          listAllUsers.Items.Add(new ListItem(user.Name, user.LoginName)); // listAllUsers is Listbox
       }
       web.AllowUnsafeUpdates = false;
    }  
}

  • Easiest option is by checking if users has a valid email address. – Amal Hashim Dec 8 '14 at 14:04
  • Ronak Patel: inside the foreach look add a condition if(!string.IsNullOrEmpty(user.Email)) then only do listAllUsers.Items.Add – Amal Hashim Dec 8 '14 at 14:12
1

The following example demonstrates how to distinguish a "regular" users in Web.SiteUsers:

public static IEnumerable<User> LoadUsers(ClientContext context)
{
   var users = context.LoadQuery(context.Web.SiteUsers.Where(u => u.PrincipalType == PrincipalType.User && u.UserId.NameIdIssuer == "urn:federation:microsoftonline"));
   context.ExecuteQuery();
   return users;
}

where:

0

Try this

ClientContext clientContext = new ClientContext("http://your site/");
Web web = clientContext.Web;
List siteUserInfoList = web.SiteUserInfoList;
CamlQuery query = new CamlQuery();
query.ViewXml = "";
IEnumerable<ListItem> itemColl = clientContext.LoadQuery(siteUserInfoList.GetItems(query));
clientContext.ExecuteQuery();
foreach (var item in itemColl)
{
    if(item["EMail"] != null && item["EMail"] != '') 
    {
        Console.WriteLine("ID:{0}  Email:{1} Title:{2}",item.Id,item["EMail"],item["Title"]);
    }
}

Get all Users with Info(LoginName,Id,Email,Title) in SharePoint 2010 Client Object Model C#

  • I have checked the Email now..but still getting this user: YLO001_spocrwl_142_11094 – Ronak Patel Dec 9 '14 at 6:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.