Partilhar via


SPWeb.Users Property

Gets the collection of user objects that are explicitly assigned permissions in the website.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online

Syntax

'Declaration
Public ReadOnly Property Users As SPUserCollection
    Get
'Usage
Dim instance As SPWeb
Dim value As SPUserCollection

value = instance.Users
public SPUserCollection Users { get; }

Property Value

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

Examples

The following code example uses the Users property to return the collection of users in a specified website of the current site collection.

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

Using webSite As SPWeb = SPContext.Current.Site.OpenWeb("Website_URL")
    Dim users As SPUserCollection = webSite.Users
    Dim user As SPUser
    For Each user In users
        Response.Write((SPEncode.HtmlEncode(user.Name) + "<BR>"))
    Next
End Using
using (SPWeb oWebsite = SPContext.Current.Site.OpenWeb("Website_URL"))
{
    SPUserCollection collUsers = oWebsite.Users;
    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