Share via


SPAlertCollection.GetUniqueUsers method

Returns a string array that lists all the users of a site, without listing them more than once, who receive alerts for list items.

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

Syntax

'Declaration
Public Function GetUniqueUsers As String()
'Usage
Dim instance As SPAlertCollection
Dim returnValue As String()

returnValue = instance.GetUniqueUsers()
public string[] GetUniqueUsers()

Return value

Type: []
A string array that contains the user name for each user.

Remarks

Warning

While this feature is still supported in the current product version, it may be removed in the future. If you write new applications, avoid using this deprecated feature. If you modify existing applications, you are strongly encouraged to remove any dependency on this feature.

Examples

The following code example shows how to return and display a list of all users who have alerts on a site.

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

The example assumes the existence of an .aspx page that contains a label control named Label1.

Dim site As SPSite = SPControl.GetContextSite(Context)
Dim web As SPWeb = site.AllWebs("Site_Name")
Dim users As String() = web.Alerts.GetUniqueUsers()
Dim user As String

For Each user In  users

    Label1.Text += SPEncode.HtmlEncode(user)

Next user 
SPSite oSiteCollection = SPContext.Current.Site;
SPWeb oWebsite = oSiteCollection.AllWebs["Site_Name"];
SPUserCollection collUsers = oWebsite.Alerts.GetUniqueUsers();

foreach (string oUser in collUsers)
{
    Label1.Text += SPEncode.HtmlEncode(oUser);
}
oWebsite.Dispose();

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

SPAlertCollection class

SPAlertCollection members

Microsoft.SharePoint namespace