locked
Counting # of users in a group? (and displaying) RRS feed

  • Question

  • Hello,


    I am attempting to count the number of users who have specified access to a subsite or group. Ideally I would like to count the users based on the group they are a part of. This sum/number would then be documented and displayed and stored somewhere as a value.  If this value hit a certain threshold, a flag or prompt would show. (KPI?)

    Each group has its own security and access to its site (subsite).

    Is this feasible? What would one need to do to achieve this?
    thanks!

    • Moved by Mike Walsh FIN Monday, January 23, 2012 2:05 PM off-topic sp 2010 q in pre-SP 2010 forum (From:SharePoint - General Question and Answers and Discussion (pre-SharePoint 2010))
    Wednesday, January 11, 2012 7:40 PM

Answers

  • You have to be aware that Direct SQL Queries to SharePoint database is not recommanded/supported (even read)

    From this article: http://support.microsoft.com/kb/841057

    Read Operations Addendum
    Reading from the SharePoint databases programmatically, or manually, can cause unexpected locking within Microsoft SQL Server which can adversely affect performance. Any read operations against the SharePoint databases that originate from queries, scripts, .dll files (and so on) that are not provided by the Microsoft SharePoint Development Team or by Microsoft SharePoint Support will be considered unsupported if they are identified as a barrier to the resolution of a Microsoft support engagement.

    Serge


    Serge Tremblay MVP SharePoint
    • Marked as answer by Wayne Fan Monday, January 23, 2012 7:48 AM
    Sunday, January 22, 2012 5:02 PM

All replies

  • Hi,

    Here you go:

    using (SPSite site = new SPSite("YourSiteUrl"))
                {
                    SPWeb web = site.OpenWeb();
                    SPGroup group = web.Groups["YourGroupName"];
                    SPUserCollection users = group.Users;
    
                    int count = users.Count;
        //Your reporting logic
    }
    
    I hope this will help you out.


    Thanks, Rahul Rashu
    Thursday, January 12, 2012 3:47 AM
  • Thanks for the reply. Excuse myself as I am quite new to customizing SP. But it looks like that is some code, to run the count. Where/How does one have the ability to write in a programming language to provide values/output?  Or if you have a referenced solution on how to do simple solutions, I could learn from that.  Could the users possibly be stored in a SQL database?

    Thanks again!


    • Edited by LetsSharePoints Thursday, January 12, 2012 5:31 AM
    • Marked as answer by Wayne Fan Monday, January 23, 2012 7:48 AM
    • Unmarked as answer by Wayne Fan Monday, January 23, 2012 7:48 AM
    Thursday, January 12, 2012 5:30 AM
  • You got to create a Visual Studio "SharePoint solution" there visual webpart wnd then add the above piece of code and deploy to your site

     

    Friday, January 13, 2012 10:55 AM
  • In case anyone was wondering, there are tables which hold the group, members in groups, member information in the content DBs. This site has a good summary here.

    http://www.sharepointkings.com/2008/06/sql-queries-for-sharepoint-content.html

    You can then run a SQL query joining the tables. I used the query to create an external list in Sharepoint Designer 2010.

    Thanks.

    Saturday, January 21, 2012 8:47 PM
  • You have to be aware that Direct SQL Queries to SharePoint database is not recommanded/supported (even read)

    From this article: http://support.microsoft.com/kb/841057

    Read Operations Addendum
    Reading from the SharePoint databases programmatically, or manually, can cause unexpected locking within Microsoft SQL Server which can adversely affect performance. Any read operations against the SharePoint databases that originate from queries, scripts, .dll files (and so on) that are not provided by the Microsoft SharePoint Development Team or by Microsoft SharePoint Support will be considered unsupported if they are identified as a barrier to the resolution of a Microsoft support engagement.

    Serge


    Serge Tremblay MVP SharePoint
    • Marked as answer by Wayne Fan Monday, January 23, 2012 7:48 AM
    Sunday, January 22, 2012 5:02 PM
  • I had just deleted a reply in this thread saying the poster of that reply used SPD 2010.

    Then I saw that it was from the person who started this thread.

    He should be aware that SP 2010 questions (and if he is using SPD 2010, that is what he is asking about) do NOT go to a pre-SP 2010 forum.

    Moving to Off-topic.

    Moderator pre-SP 2010 forums.


    SP 2010 "FAQ" (mainly useful links): http://wssv4faq.mindsharp.com/default.aspx
    WSS3/MOSS FAQ (FAQ and Links) http://wssv3faq.mindsharp.com/default.aspx
    Both also have links to extensive book lists and to (free) on-line chapters
    Monday, January 23, 2012 2:04 PM