Skip to main content

Harsh's Blog

Go Search
Blogs
  

Other Blogs
There are no items in this list.
Blogs > Harsh's Blog > Posts > Retrieving User Alerts via Object Model
Retrieving User Alerts via Object Model

Take a look at this screen.


This is a typical screen when a user is setting up Alerts. The SPAlert object allows easy access to the Change Type, via alert.EventType. However, the alert object model does not very intuitively allow accessing the next group of settings. Say for instance, you wish to deploy a web part that will display all the Alerts configured for the user along with providing the ability to filter out these alerts based on "what has changed".

The SPAlert object returns a PropertyBag of sorts via the SPAlert.Properties[1] method. This PropertyBag (which actually is a Microsoft.SharePoint.Utilities.SPPropertyBag [2]) contains a host of information related to the alert.

SPWeb web SPControl.GetContextWeb(Contex);
SPUser user web.CurrentUser;
SPAlertCollection alertColl web.Alerts;
foreach 
(SPAlert alert in alertColl)
{
    
if (alert.User == user)
      {
        
switch (alert.Properties["filterindex"]){
            
// multiple cases involved based on what list it was worked on
        
}
    }
}



Here's what the switch…case can use:

List Type

Filterindex options

Index

Value

Announcements

0

Anything changes

 

1

Someone else changes an announcement

 

2

Someone else changes an announcement created by me

 

3

Someone else changes an announcement last modified by me

 

4

An announcement with an expiration date is added or changed

     

Calendar

0

Anything changes

 

1

Someone else changes an event

 

2

Someone else changes an event created by me

 

3

Someone else changes an event last modified by me

 

4

The time or location of an event changes

     

Links

0

Anything changes

 

1

Someone else changes a link

 

2

Someone else changes a link created by me

 

3

Someone else changes a link last modified by me

     

Tasks

0

Anything changes

 

1

A task is assigned to me

 

2

A task becomes complete

 

3

A high priority task changes

 

4

Someone else changes a task assigned to me

 

5

Someone else changes a task

 

6

Someone else changes a task created by me

 

7

Someone else changes a task last modified by me

 

8

Someone changes an item that appears in a view*

     

Discussion Board

0

Anything changes

 

1

Someone else changes a post

 

2

Someone else changes a post created by me

 

3

Someone else changes a post last modified by me

     

Form Library

0

Anything changes

 

1

Someone else changes a document

 

2

Someone else changes a document created by me

 

3

Someone else changes a document last modified by me

 

4

Someone else changes an item that appears in a view*

     

Wiki Page Library

0

Anything changes

 

1

Someone else changes a wiki page

 

2

Someone else changes a wiki page created by me

 

3

Someone else changes a wiki page last modified by me

 

4

Someone else changes an item that appears in a view*

     

Picture Library

0

Anything changes

 

1

Someone else changes a picture

 

2

Someone else changes a picture created by me

 

3

Someone else changes a picture last modified by me

     

 

Comments

There are no comments yet for this post.
Items on this list require content approval. Your submission will not appear in public views until approved by someone with proper rights. More information on content approval.

Title


Name (required) *


URL

Type the Web address: (Click here to test)  

Type the description: 

Body *


Attachments