This project has moved and is read-only. For the latest updates, please go here.
1

Closed

Add support to load all external users

description

i fixed this issue, can you please update this method to load all external user
public static void LoadExternalUsers(TreeNode parentNode, SPTenantMngt.Office365Tenant tenant, MainForm form, NodeLoadType loadType)
        {
            try
            {
                SPClient.ClientContext ctx = GetClientContext(parentNode);

                // TODO: Fix issue with pagesize, this needs to be increased and recursive to collect all external users
                int position = 0;
                bool hasMore = true;
                while (hasMore)
                {

                    SPTenantMngt.GetExternalUsersResults results = tenant.GetExternalUsers(position, 50, string.Empty, SPTenantMngt.SortOrder.Ascending);
                    ctx.Load(results, 
                        r=>r.ExternalUserCollection.Include(k=>k.InvitedBy),
                        r => r.UserCollectionPosition,
                        r => r.TotalUserCount,
                        r => r.ExternalUserCollection);
                    ctx.ExecuteQuery();

                    int total = results.TotalUserCount;
                    int current = 0;

                    // Add count to parent node
                    UpdateCountChildNodes(parentNode, total);

                    // Add external users to parent node


                    foreach (SPTenantMngt.ExternalUser user in results.ExternalUserCollection)
                    {
                        
                        position++;
                        TreeNode node = AddTreeNode(parentNode, string.Format("{0} ({1})", user.DisplayName, user.InvitedAs), user, Constants.IMAGE_EXTERNAL_USERS, "Represents an external user in Office 365.", form.mnContextItem);

                        // Update progress
                        current++;
                        ItemLoaded(null, new ItemLoadedEventArgs() { TotalItem = total, CurrentItem = current });
                    }
                    hasMore = (results.TotalUserCount > position);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, form.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                LogUtil.LogException(ex);

                AddLoadingNode(parentNode, loadType);
            }
        }
Closed Feb 1 at 7:46 AM by BdeJager
New release is available as of yesterday. This includes the update.

comments

BdeJager wrote Jan 17 at 7:55 AM

Hi SlimMehrez, thanks for the suggestion. I have made changes to the sources and it will be included in the new release. Regards Bram

BdeJager wrote Feb 1 at 7:45 AM

New release is available as of yesterday. This includes your fix.

wrote Feb 1 at 7:46 AM