Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
SDK Documentation
SPWeb Class
SPWeb Properties
 Users Property
Community Content
In this section
Statistics Annotations (0)
Collapse All/Expand All Collapse All
This page is specific to
The 2007 product release

Other versions are also available for the following:
SPWeb.Users Property (Microsoft.SharePoint)
Gets the collection of user objects that are explicitly assigned permissions in the Web site.

Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in microsoft.sharepoint.dll)
Visual Basic (Declaration)
Public ReadOnly Property Users As SPUserCollection
Visual Basic (Usage)
Dim instance As SPWeb
Dim value As SPUserCollection

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

Property Value

An SPUserCollection object that represents the users.

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

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

Visual Basic
Using webSite As SPWeb = SPContext.Current.Site.OpenWeb("Website_URL")
    Dim users As SPUserCollection = site.Users
    Dim user As SPUser
    For Each user In users
        Response.Write((SPEncode.HtmlEncode(user.Name) + "<BR>"))
    Next
End Using
C#
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 Best Practices: Using Disposable Windows SharePoint Services Objects.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker