So I am trying to build an equivalent to a People Picker in Windows.Forms Application. Since 2010 does not have Web.SiteUsers like 2013 does I had to write it like this.

public UserPicker(string SiteUrl)
    ClientContext clientContext = new ClientContext(SiteUrl);
    Web web = clientContext.Web;
    List siteUserInfoList = web.SiteUserInfoList;
    CamlQuery query = new CamlQuery();
    query.ViewXml = "";
    IEnumerable<ListItem> itemColl = clientContext.LoadQuery(siteUserInfoList.GetItems(query));
    foreach (var item in itemColl)
        if (item["UserName"] != null)
            UserList.Items.Add(item["Title"] + "-" + item["UserName"]);

Where UserList is a ListBox object from Windows.Forms. The problem is this is SUPER slow for 5k+ users. Like over 10 seconds. PLUS its sorted by ID by default so sorting it by Title which I want to do would add even more overhead.

There has got to be a better way.. I saw the MSDN article https://msdn.microsoft.com/en-us/library/office/ee538244%28v=office.14%29.aspx titled Retrieve all users in all groups in a site collection.. But this won't work because there are some groups I don't have read access to so I get ServerUnauthorizedAccessException. Plus I want this tool to be adding new users to groups (right now I have that functionality by just typing their "DOMAIN/USERNAME" into a text box.) so there should be a possibility of a user not existing in any groups while performing this query.

Any Ideas on how to achieve what I am attempting? It has to have been done before.. But I can't seem to find examples on the web. To sum up my desired requirements..

  • Include all users with non-null UserName in some selection box.
  • Order alphabetically
  • Include some search which narrows down the options (Like ComboBox)
  • Runtime less than a few seconds
  • Try getting the User information list items using lists.asmx web service and check the time taken for that operation. – Akhoy Jul 29 '15 at 17:05
  • I've done that with javascript. Not with C#. Do you know of a good reference with examples to work off of? I can test it out real fast. – Riggy Jul 29 '15 at 17:14
  • ojasmaru.blogspot.in/2012/08/… – Akhoy Jul 29 '15 at 17:31
  • I can't seem to get past the "The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'NTLM'." Error.. the app.config contents they included don't match up with what I have... – Riggy Jul 29 '15 at 18:02
  • Try giving the credentials in C# itself without making changes in config file. sarangasl.blogspot.in/2009/12/sharepoint-list-web-service.html – Akhoy Jul 29 '15 at 18:10

Your Answer

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

Browse other questions tagged or ask your own question.