1

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();

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 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();
1

Try to change the AlertType from AlertType.List to SPAlertType.Item, then set the listitem to newAlert.Item

newAlert.AlertType = SPAlertType.Item;
newAlert.Item = list.GetItemById(1);
  • i updated the code but still am getting alert on the list and the folder..i want alert only on the folder – Keshav Taurah Oct 6 '17 at 12:07
  • Okay, let me recheck it on my side and feedback you ASAP – Mohamed El-Qassas MVP Oct 6 '17 at 12:50
  • ok i check multiple time,i get an alert only when creating a folder(the folder that the alert is attached to),if add a file in that folder no alert – Keshav Taurah Oct 9 '17 at 5:56
  • if i change the name of the folder i get an alert,AGAIN if i add a document inside that folder no alert. – Keshav Taurah Oct 9 '17 at 6:31
  • could you try to add alert for a folder via browser and check if you will get the same behavior or not! , I'm afraid, maybe it's normal where the alert raise on an item/list, in your case the folder is considered an item it doesn't care about its content! – Mohamed El-Qassas MVP Oct 9 '17 at 7:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.