Partager via


IAlertNotifyHandler.OnNotification - Méthode

Se produit après qu'une alerte est envoyée et renvoie des informations sur la notification d'alerte.

Espace de noms :  Microsoft.SharePoint
Assembly :  Microsoft.SharePoint (dans Microsoft.SharePoint.dll)

Syntaxe

'Déclaration
Function OnNotification ( _
    ahp As SPAlertHandlerParams _
) As Boolean
'Utilisation
Dim instance As IAlertNotifyHandler
Dim ahp As SPAlertHandlerParams
Dim returnValue As Boolean

returnValue = instance.OnNotification(ahp)
bool OnNotification(
    SPAlertHandlerParams ahp
)

Paramètres

Valeur renvoyée

Type : System.Boolean
true si SharePoint Foundation marque la notification comme traité ; dans le cas contraire, false.

Remarques

Créez une classe qui hérite de l'interface IAlertNotificationHandler et utilise la méthode OnNotification . Cela vous permet d'intercepter les alertes électroniques sortants et les modifier. Nous pouvons accéder à la plupart des propriétés de l'alerte et une analyse de XML et le code de modèle d'objet SharePoint, nous pouvons extraire toutes les informations dont nous avons besoin pour créer le message électronique. Utilisez ces informations pour construire le stub HTML pour afficher le message en fonction de vos besoins et à envoyer l'e-mail à l'aide de la fonctionnalité de SharePoint SendMail.

L'exemple met en forme la sortie pour ressembler autant que possible à l'e-mail du modèle d'alerte par défaut, vous pouvez personnaliser davantage pour répondre à vos besoins.

Notes

Incluez les espaces de noms Microsoft.SharePoint et Microsoft.SharePoint.Utilities dans le projet.

Exemples

    public class Class1:IAlertNotifyHandler
    {
        #region IAlertNotifyHandler Members
        public bool OnNotification(SPAlertHandlerParams ahp)
        {
            try
            {
                SPSite site = new SPSite(ahp.siteUrl+ahp.webUrl);
                SPWeb web = site.OpenWeb();
                SPList list=web.Lists[ahp.a.ListID];
                SPListItem item = list.GetItemById(ahp.eventData[0].itemId) ;
                
                string FullPath=HttpUtility.UrlPathEncode(ahp.siteUrl+"/"+ahp.webUrl+"/"+list.Title+"/"+item.Name);
                string ListPath = HttpUtility.UrlPathEncode(ahp.siteUrl + "/" + ahp.webUrl + "/" + list.Title);
                string webPath=HttpUtility.UrlPathEncode(ahp.siteUrl+"/"+ahp.webUrl);
                
                string build = "";
                 if (ahp.eventData[0].eventType==1)
                 eventType="Added";
                 else if(ahp.eventData[0].eventType==2)
                 eventType="Changed";
                 else if(ahp.eventData[0].eventType==3)
                 eventType="Deleted";

         build = "<style type=\"text/css\">.style1 {font-size: small;       border: 1px solid #000000;"+
         "background-color: #DEE7FE;}.style2 {               border: 1px solid #000000;}</style></head>"+                    
         "<p><strong>"+ item.Name.ToString() +"</strong> has been "+eventType +"</p>"+
         "<table style=\"width: 100%\" class=\"style2\"><tr><td style=\"width: 25%\" class=\"style1\">"+
         "<a href="+ webPath +"/_layouts/mysubs.aspx>Modify my Settings</a></td>"+
                  "<td style=\"width: 25%\" class=\"style1\"> 
                   <a href="+ FullPath +">View "+item.Name+"</a></td>"+
                    "<td style=\"width: 25%\" class=\"style1\"><a href=" + ListPath + ">View " + list.Title + "</a></td>" +
                    "        </tr></table>";
                string subject=list.Title.ToString() ;               
                SPUtility.SendEmail(web,true , false, ahp.headers["to"].ToString(), subject,build);
                return false;
            }
            catch (System.Exception ex)
            {
                return false;
            }
        }
        #endregion
    }

Voir aussi

Référence

IAlertNotifyHandler interface

IAlertNotifyHandler - Membres

Microsoft.SharePoint - Espace de noms