Tuesday, February 7, 2012

Sharepoint 2010 Alerts

By default alerts can be send only through e-mail. But we can change that default setting by using the new DeliveryChannels Property of SPAlert class. This DeliveryChannels property, specifies the delivery method of the alert.


The following snippet used to set the SMS delivery method to the Alert.

oAlert.DeliveryChannels = SPAlertDeliveryChannels.Sms;


SPAlertDeliveryChannels is the enumerated member, which specifies the method of delivering alerts.

Email-Delivery as E-mail
Sms-Delivery as SMS Message

The following example code used to update the sms delivery method to all the alerts for every user available in Current website.

SPWeb oWebsite = SPContext.Current.Web;
SPUserCollection collUsers = oWebsite.Users;
foreach (SPUser oUser in collUsers)
{
SPAlertCollection collAlerts = oUser.Alerts;
foreach (SPAlert oAlert in collAlerts)
{
oAlert.DeliveryChannels = SPAlertDeliveryChannels.Sms;
oAlert.Update();
}
}

Enjoi...

1 comment:

  1. Hi! I'd like to know how to specify the phone number in the SPALert when using SPAlertDeliveryChannels.Sms

    Thanks

    ReplyDelete