dekempeneer
asked on
create sharepoint alert
I can create an alert for a user, but how can I do it for a security group ?
the code I attach here works for the user, but how do I do it for a GROUP ?
the code I attach here works for the user, but how do I do it for a GROUP ?
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
namespace Create_Alerts_Sharepoint
{
public class Class1
{
static void Main(string[] args)
{
using (SPSite site = new SPSite("http://shdev01/kp"))
{
using (SPWeb web = site.OpenWeb())
{
SPUser user = web.SiteUsers[@"DOMAIN\user"];
SPAlert newAlert = user.Alerts.Add();
newAlert.Title = "Latest News";
newAlert.AlertType = SPAlertType.List;
newAlert.List = web.Lists["Carrefour"];
newAlert.EventType = SPEventType.All;
newAlert.AlertFrequency = SPAlertFrequency.Daily;
newAlert.AlertTime = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 12, 0, 0);
newAlert.AlertTime = newAlert.AlertTime.AddDays(1);
newAlert.Update(false);
}
}
}
}
}
ASKER
It is an AD email enabled group, I can set the alert from within sharepoint itself, but then all users from that group receive an email that they are subscribed to that alert. Using code I can avoid this.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
use SPGroup instead of SPuser
SPWeb oWebsite = SPContext.Current.Site.Roo tWeb
{ SPGroup oGroup = oWebsite.SiteGroups["Origi nal_Name"] ;
}
SPWeb oWebsite = SPContext.Current.Site.Roo
{ SPGroup oGroup = oWebsite.SiteGroups["Origi
}
ASKER
That was it, I needed to add this usergroup to the Visitors group.
Dear ALL
could you please let me know how to use this code in sharepoint site? i just created a sharepoint site use HelpDesk template download from Microsoft, and i would like to setup alert, if anyone create a new request, the sharepoint can send me notification email.
could you please let me know how to use this code in sharepoint site? i just created a sharepoint site use HelpDesk template download from Microsoft, and i would like to setup alert, if anyone create a new request, the sharepoint can send me notification email.
depends what you refer to as group. Check this site http://danishhussain.blogspot.com/2009/07/sending-alerts-to-group-using-share.html about adding groups to alerts in SahrePoint in general. Out of the box you can only use AD email enabled groups but not SharePoint groups.