Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

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)
public SPUserCollection Users { get; }

Property value

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

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 (SPWeb oWebsite = SPContext.Current.Site.OpenWeb("Website_URL"))
{
    SPUserCollection collUsers = oWebsite.Users;
    foreach (SPUser oUser in collUsers)
    {
        Response.Write(SPEncode.HtmlEncode(oUser.Name) + "<BR>");
    }
}
NoteNote

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.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.