bramdejager / spcb

The SharePoint Client Browser (SPCB) uses the CSOM to connect to a remote SharePoint site collection and shows the site structure with related properties and values.
GNU General Public License v2.0
174 stars 48 forks source link

Add support to load all external users #52

Closed bramdejager closed 6 years ago

bramdejager commented 6 years ago

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);
        }
    }

This work item was migrated from CodePlex

CodePlex work item ID: '65845' Vote count: '1'

bramdejager commented 6 years ago

[BdeJager@16-1-2017] Hi SlimMehrez, thanks for the suggestion. I have made changes to the sources and it will be included in the new release. Regards Bram

bramdejager commented 6 years ago

[BdeJager@31-1-2017] New release is available as of yesterday. This includes your fix.

bramdejager commented 6 years ago

[UnknownUser@31-1-2017]

bramdejager commented 6 years ago

Issue closed by BdeJager with comment New release is available as of yesterday. This includes the update.

Reason closed Fixed