public SPAlertCollectionInstance(ObjectInstance prototype, SPAlertCollection alertCollection) : this(prototype) { if (alertCollection == null) { throw new ArgumentNullException("alertCollection"); } m_alertCollection = alertCollection; }
public AlertCollectionNode(Object parent, SPAlertCollection collection) { this.Text = SPMLocalization.GetString("AlertCollection_Text"); this.ToolTipText = SPMLocalization.GetString("AlertCollection_ToolTip"); this.Name = "AlertCollection"; this.Tag = collection; this.SPParent = parent; int index = Program.Window.Explorer.AddImage(this.ImageUrl()); this.ImageIndex = index; this.SelectedImageIndex = index; this.Nodes.Add(new ExplorerNodeBase("Dummy")); }
private void RemoveAlerts(XmlNode siteNode, string url) { using (SPWeb web = new SPSite(url).OpenWeb()) { SPClaimProviderManager cpm = SPClaimProviderManager.Local; SPClaim userClaim = cpm.ConvertIdentifierToClaim("emirates\\s717981", SPIdentifierTypes.WindowsSamAccountName); SPUser tempUser = web.EnsureUser(userClaim.ToEncodedString()); web.AllowUnsafeUpdates = true; try { SPAlertCollection allAlerts = web.Alerts; List <Guid> alertsToDelete = new List <Guid>(); foreach (SPAlert spAlert in allAlerts) { alertsToDelete.Add(spAlert.ID); } Guid [] alerts = alertsToDelete.ToArray(); for (int i = 0; i < alerts.Length; i++) { SPAlert alert = allAlerts[alerts[i]]; alert.User = tempUser; alert.Status = SPAlertStatus.Off; alert.Update(); } foreach (Guid alertGuid in alertsToDelete) { allAlerts.Delete(alertGuid); } web.Update(); } catch (Exception ex) { Console.WriteLine(ex.Message); } web.AllowUnsafeUpdates = false; } }
static void Main(string[] args) { SPSite site = new SPSite("http://chiron"); SPWeb web = site.AllWebs["CodeDemo"]; SPUser user = web.CurrentUser; foreach (SPAlert alert in user.Alerts) { Debug.WriteLine(alert.AlertType); if (alert.AlertType == SPAlertType.List) { //user.Alerts.Delete(alert.ID); } } SPAlertCollection alerts = web.Alerts; SPList list = web.Lists["Documents"]; // get the lists alert template and apply that to the new alert SPAlertTemplate alertTemplate = list.AlertTemplate; alertTemplate.Name = list.AlertTemplate.Name; // setup the alert SPAlert a = alerts.Add(); a.AlertType = SPAlertType.List; a.AlertTemplate = alertTemplate; a.Title = "Demo Title"; a.EventType = SPEventType.Add; a.AlertFrequency = SPAlertFrequency.Immediate; a.AlwaysNotify = false; a.User = user; a.List = list; a.Update(true); }
Result iTool.Execute(Job job) { Result result = new Result(job.Id); config permConfig = new config(); notifications siteNotifications = new notifications(); permConfig.ReadConfig(job.DownloadAttachment()); List <site> sites = new List <site>(); foreach (alertsite permSite in permConfig.alertSites) { using (SPWeb web = new SPSite(permSite.source).OpenWeb()) { try { Console.WriteLine(web.Url); site site = new site(permSite.source, permSite.target); SPListCollection siteLists = web.Lists; SPAlertCollection allAlerts = web.Alerts; Console.WriteLine(allAlerts.Count); foreach (SPAlert spAlert in allAlerts) { try { if (spAlert.AlertType == SPAlertType.List) { string filterpath = spAlert.Properties["Filterpath"] as string; string objectType = "list"; bool isFolder = !String.IsNullOrEmpty(filterpath); Helper helper = Helper.Instance; if (!string.IsNullOrEmpty(filterpath)) { filterpath = helper.MapServerRelativeUrl( string.Format("/{0}", filterpath).ToLower(), permSite.source, permSite.target); objectType = "folder"; } site.AddAlert(spAlert.Title, spAlert.User.LoginName, spAlert.List.Title, spAlert.EventType.ToString(), spAlert.AlertFrequency.ToString(), spAlert.AlertType.ToString(), filterpath, objectType); } else { string url = (spAlert.List.BaseType == SPBaseType.DocumentLibrary) ? spAlert.Item.File.ServerRelativeUrl : spAlert.Item.Url; string objectType = (spAlert.List.BaseType == SPBaseType.DocumentLibrary) ? "file" : "item"; Helper helper = Helper.Instance; string updatedUrl = helper.MapServerRelativeUrl(url, permSite.source, permSite.target); url = updatedUrl; site.AddAlert(spAlert.Title, spAlert.User.LoginName, spAlert.List.Title, spAlert.EventType.ToString(), spAlert.AlertFrequency.ToString(), spAlert.AlertType.ToString(), spAlert.ItemID, url, objectType); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } siteNotifications.sites.Add(site); } catch (Exception ex) { Console.WriteLine(ex.Message); } } } XmlSerializer serializer = new XmlSerializer(typeof(notifications)); string tmpFile = Scheduler.Instance.CreateTmpFile(); using (TextWriter writer = new StreamWriter(tmpFile)) { serializer.Serialize(writer, siteNotifications); } result.AddFile(tmpFile); return(result); }