Code to subscribe the User for alert notifications from a list

    1:          SPWeb web = SPContext.Current.Web;
    2:   
    3:          SPList list = web.Lists["Pages"];
    4:   
    5:          SPUser user = web.CurrentUser;
    6:   
    7:          SPAlert alert = user.Alerts.Add();
    8:   
    9:          alert.Title = "My Alert";
   10:   
   11:          alert.AlertType = SPAlertType.List;
   12:   
   13:          alert.EventType = SPEventType.All;
   14:   
   15:          alert.List = list;
   16:   
   17:          alert.AlertFrequency = SPAlertFrequency.Immediate;
   18:   
   19:          alert.AlwaysNotify = true;
   20:   
   21:          alert.Update(true); // Subscription notification will be sent to user
   22:   
   23:          //alert.Update(false); // Subscription notification will not be sent to user