Share via


How to get users under a subsite/area in WSS 2.0/SPS 2003?

Although it seems a very basic question, but I thought of blogging this as it is not as easy as it is in MOSS 2007. Normally our approach would be to use the SPWeb object to represent the sub site and then iterate through the list of users in the SPWeb object. Surprise! Surprise! This doesn’t give you the correct list and if you try to go to the sub site in the UI and check the users that would be entirely different.

So to get the sub site/area users the following code can be used.

<Code>

TopologyManager tm = new TopologyManager();

                PortalSite ps = tm.PortalSites[new Uri("https://Moss12:1000")];

                Microsoft.SharePoint.Portal.PortalContext ctx = Microsoft.SharePoint.Portal.PortalApplication.GetContext(ps);

                Guid NewsGuid = AreaManager.GetSystemAreaGuid(ctx, SystemArea.Topics);

                PermissionCollection pc = SecurityManager.ManageAreaSecurity(ctx, NewsGuid);

                foreach (Permission pm in pc)

                {

                    User usr = pm.Member as User;

                    Role role = pm.Member as Role;

                    SPRole roles = pm.Member as SPRole;

                    if (usr != null)

                    {

                        Console.WriteLine("User Email: " + usr.Name);

                    }

                    else

                    {

                        Console.WriteLine("Role name: " + role.Name);

                        Console.WriteLine(pm.PortalMask);

                    }

                }

</Code>

Comments