Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

SpUser.Alerts

  Asked By: Harley    Date: Jun 12    Category: Sharepoint    Views: 2220

I am trying to programmatically to add alerts for users of a Site. I have
created the following code, which is a modification of the example code. When I
add the alert on the list, it adds for SHAREPOINT\system user multiple times.

Example code - msdn2.microsoft.com/en-us/library/ms438045.aspx


private void SetNotificationFor(string PrimaryOwner, string SecondaryOwner,
string ContentAuth)
{
System.Diagnostics.Debug.WriteLine("\tMicron.MOSS2007.TrainingSite
- Entering SetNotificationFor PrimaryOwner " + PrimaryOwner);
System.Diagnostics.Debug.WriteLine("\tMicron.MOSS2007.TrainingSite
- Entering SetNotificationFor SecondaryOwner " + SecondaryOwner);
System.Diagnostics.Debug.WriteLine("\tMicron.MOSS2007.TrainingSite
- Entering SetNotificationFor ContentAuth " + ContentAuth);
try
{
foreach (Microsoft.SharePoint.SPUser spUser in
rootWeb.SiteUsers)
{

System.Diagnostics.Debug.WriteLine("\tMicron.MOSS2007.TrainingSite - Entering
SetNotificationFor " + spUser.LoginName);
if (spUser.LoginName.Contains(PrimaryOwner))
{

System.Diagnostics.Debug.WriteLine("\tMicron.MOSS2007.TrainingSite - Entering
SetNotificationFor PrimaryOwner " + PrimaryOwner);
try
{
spUser.Alerts.Add(this.notificationList,
SPEventType.All, SPAlertFrequency.Immediate);
}
catch (Exception e2)
{

System.Diagnostics.Debug.WriteLine("\tMicron.MOSS2007.TrainingSite -
SetNotificationFor e2 " + e2.Message);
}
}
if (spUser.LoginName.Contains(SecondaryOwner))
{

System.Diagnostics.Debug.WriteLine("\tMicron.MOSS2007.TrainingSite - Entering
SetNotificationFor SecondaryOwner " + SecondaryOwner);
try
{
spUser.Alerts.Add(this.notificationList,
SPEventType.All, SPAlertFrequency.Immediate);
}
catch (Exception e2)
{

System.Diagnostics.Debug.WriteLine("\tMicron.MOSS2007.TrainingSite -
SetNotificationFor e2 " + e2.Message);
}
}
if (spUser.LoginName.Contains(ContentAuth))
{

System.Diagnostics.Debug.WriteLine("\tMicron.MOSS2007.TrainingSite - Entering
SetNotificationFor ContentAuth " + ContentAuth);
try
{
spUser.Alerts.Add(this.notificationList,
SPEventType.All, SPAlertFrequency.Immediate);
}
catch (Exception e2)
{

System.Diagnostics.Debug.WriteLine("\tMicron.MOSS2007.TrainingSite -
SetNotificationFor e2 " + e2.Message);
}
}
}
}
catch (Exception e1)
{

System.Diagnostics.Debug.WriteLine("\tMicron.MOSS2007.TrainingSite -
SetNotificationFor e1" + e1.Message);
}
System.Diagnostics.Debug.WriteLine("\tMicron.MOSS2007.TrainingSite
- Exiting SetNotificationFor");
}

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Anibal Baird     Answered On: Jun 12

I found the answer to my own question. Here is the code  for how to do it the
new way

Microsoft.SharePoint.SPAlert spAlert = spUser.Alerts.Add();
spAlert.AlertType = Microsoft.SharePoint.SPAlertType.List;
spAlert.List = notificationList;
spAlert.EventType = Microsoft.SharePoint.SPEventType.All;
spAlert.AlertFrequency = Microsoft.SharePoint.SPAlertFrequency.Immediate;
spAlert.Title = "Announcements";
spAlert.Update(true);

 
Didn't find what you were looking for? Find more on SpUser.Alerts Or get search suggestion and latest updates.




Tagged: