Share via


SPWeb.SiteUsers property

Gets the collection of all users that belong to the site collection.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

public SPUserCollection SiteUsers { get; }

Property value

Type: Microsoft.SharePoint.SPUserCollection
An SPUserCollection object that represents the users.

Examples

The following code example uses the SiteUsers property to return the collection of users for the current site collection and the user display names

This example requires using directives (Imports in Microsoft Visual Basic) for the Microsoft.SharePoint and Microsoft.SharePoint.Utilities namespaces.

using (SPWeb oWebsite = SPContext.Current.Site.OpenWeb("Website_URL"))
{
    SPUserCollection collUsers = oWebsite.SiteUsers;
    foreach (SPUser oUser in collUsers)
    {
        Response.Write(SPEncode.HtmlEncode(oUser.Name) + "<BR>");
    }
}

Note

Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Disposing Objects.

See also

Reference

SPWeb class

SPWeb members

Microsoft.SharePoint namespace