Export (0) Print
Expand All

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)

public string[] GetUniqueUsers()

Return value

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

Caution noteCaution

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.

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.

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();
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.

Show:
© 2015 Microsoft