3 added 1420 characters in body
source | link

updated code using list itself and trying to filter event

 AlertCreationInformation myNewAlert = new AlertCreationInformation();

               // myNewAlert.Item = companylibrary.GetItemByUniqueId(alertfolder.UniqueId);
                myNewAlert.List = clientContext.Web.Lists.GetByTitle(CompanyType);
                myNewAlert.AlertFrequency = AlertFrequency.Immediate;
                myNewAlert.AlertTime = DateTime.Now;
                myNewAlert.AlertType = AlertType.List;
                myNewAlert.AlwaysNotify = true;
                myNewAlert.DeliveryChannels = AlertDeliveryChannel.Email;
                myNewAlert.EventType = AlertEventType.All;
                myNewAlert.Filter = "2";
                // 0 = Anything Changes
                // 1 = Someone else changes a document
                // 2 = Someone else changes a document created by me
                // 3 = Someone else changes a document modified by me

                myNewAlert.Status = AlertStatus.On;
                myNewAlert.Title = "My new alert created at : " + DateTime.Now.ToString();
                myNewAlert.User = clientContext.Web.CurrentUser;

                var newAlertGuid = clientContext.Web.CurrentUser.Alerts.Add(myNewAlert);

                clientContext.ExecuteQuery();

updated code using list itself and trying to filter event

 AlertCreationInformation myNewAlert = new AlertCreationInformation();

               // myNewAlert.Item = companylibrary.GetItemByUniqueId(alertfolder.UniqueId);
                myNewAlert.List = clientContext.Web.Lists.GetByTitle(CompanyType);
                myNewAlert.AlertFrequency = AlertFrequency.Immediate;
                myNewAlert.AlertTime = DateTime.Now;
                myNewAlert.AlertType = AlertType.List;
                myNewAlert.AlwaysNotify = true;
                myNewAlert.DeliveryChannels = AlertDeliveryChannel.Email;
                myNewAlert.EventType = AlertEventType.All;
                myNewAlert.Filter = "2";
                // 0 = Anything Changes
                // 1 = Someone else changes a document
                // 2 = Someone else changes a document created by me
                // 3 = Someone else changes a document modified by me

                myNewAlert.Status = AlertStatus.On;
                myNewAlert.Title = "My new alert created at : " + DateTime.Now.ToString();
                myNewAlert.User = clientContext.Web.CurrentUser;

                var newAlertGuid = clientContext.Web.CurrentUser.Alerts.Add(myNewAlert);

                clientContext.ExecuteQuery();
2 added 1547 characters in body
source | link

updated code:

string targetDocSetUrlalert = CompanyType + "/" + CompanyName;
                List list = clientContext.Web.Lists.GetByTitle(CompanyType);
                Folder alertfolder = clientContext.Web.GetFolderByServerRelativeUrl(targetDocSetUrlalert);
                clientContext.Load(clientContext.Web);
                clientContext.Load(list);
                clientContext.Load(alertfolder, x => x.UniqueId);
                clientContext.ExecuteQuery();

                AlertCreationInformation myNewAlert = new AlertCreationInformation();

                myNewAlert.Item = companylibrary.GetItemByUniqueId(alertfolder.UniqueId);

                myNewAlert.AlertFrequency = AlertFrequency.Immediate;
                myNewAlert.AlertTime = DateTime.Now;
                myNewAlert.AlertType = AlertType.Item;
                myNewAlert.AlwaysNotify = true;
                myNewAlert.DeliveryChannels = AlertDeliveryChannel.Email;
                myNewAlert.EventType = AlertEventType.All;
                myNewAlert.Filter = "0";
                myNewAlert.Status = AlertStatus.On;
                myNewAlert.Title = "My new alert created at : " + DateTime.Now.ToString();
                myNewAlert.User = clientContext.Web.CurrentUser;

                var newAlertGuid = clientContext.Web.CurrentUser.Alerts.Add(myNewAlert);

                clientContext.ExecuteQuery();

updated code:

string targetDocSetUrlalert = CompanyType + "/" + CompanyName;
                List list = clientContext.Web.Lists.GetByTitle(CompanyType);
                Folder alertfolder = clientContext.Web.GetFolderByServerRelativeUrl(targetDocSetUrlalert);
                clientContext.Load(clientContext.Web);
                clientContext.Load(list);
                clientContext.Load(alertfolder, x => x.UniqueId);
                clientContext.ExecuteQuery();

                AlertCreationInformation myNewAlert = new AlertCreationInformation();

                myNewAlert.Item = companylibrary.GetItemByUniqueId(alertfolder.UniqueId);

                myNewAlert.AlertFrequency = AlertFrequency.Immediate;
                myNewAlert.AlertTime = DateTime.Now;
                myNewAlert.AlertType = AlertType.Item;
                myNewAlert.AlwaysNotify = true;
                myNewAlert.DeliveryChannels = AlertDeliveryChannel.Email;
                myNewAlert.EventType = AlertEventType.All;
                myNewAlert.Filter = "0";
                myNewAlert.Status = AlertStatus.On;
                myNewAlert.Title = "My new alert created at : " + DateTime.Now.ToString();
                myNewAlert.User = clientContext.Web.CurrentUser;

                var newAlertGuid = clientContext.Web.CurrentUser.Alerts.Add(myNewAlert);

                clientContext.ExecuteQuery();
1
source | link

set up alert on folder using csom

My scenario, i can already set up alert on a list using the code below but i want to only set alert on specific document library inside the list.

                AlertCreationInformation myNewAlert = new AlertCreationInformation();

                myNewAlert.List = clientContext.Web.Lists.GetByTitle(CompanyName);
                myNewAlert.AlertFrequency = AlertFrequency.Immediate;
                myNewAlert.AlertTime = DateTime.Now;
                myNewAlert.AlertType = AlertType.List;
                myNewAlert.AlwaysNotify = true;
                myNewAlert.DeliveryChannels = AlertDeliveryChannel.Email;
                myNewAlert.EventType = AlertEventType.All;
                myNewAlert.Filter = "0";
                myNewAlert.Status = AlertStatus.On;
                myNewAlert.Title = "My new alert created at : " + DateTime.Now.ToString();
                myNewAlert.User = clientContext.Web.CurrentUser;

                var newAlertGuid = clientContext.Web.CurrentUser.Alerts.Add(myNewAlert);

                clientContext.ExecuteQuery();