goran ljubic

goran ljubic

  • NA
  • 27
  • 3k

Event Receiver for item deleting in calendar

Sep 28 2018 3:39 AM
I have two calendars, I created workflow that creates item to second calendar when item created in first calendar. in second calendar i created column 'Id odsustvo' where the workflow set item id of first list. I tryed that create event receiver, but he is not working. i cannot delete item in second list when is deleted item in first list. code is next
  1. using System;    
  2. using System.Security.Permissions;    
  3. using Microsoft.SharePoint;    
  4. using Microsoft.SharePoint.Security;    
  5. using Microsoft.SharePoint.Utilities;    
  6. using Microsoft.SharePoint.Workflow;    
  7.     
  8. namespace brisanje_stavke_iz_karneta_eventreceiver.EventReceiver1    
  9. {    
  10.     ///     
  11.     /// List Item Events    
  12.     ///     
  13.     public class EventReceiver1 : SPItemEventReceiver    
  14.     {    
  15.         private static string ID;    
  16.         ///     
  17.        /// An item is being deleted.    
  18.        ///     
  19.        public override void ItemDeleting(SPItemEventProperties properties)    
  20.        {    
  21.            base.ItemDeleting(properties);    
  22.            ID = properties.ListItem["ID"].ToString();    
  23.        }    
  24.     
  25.        ///     
  26.        /// An item was deleted.    
  27.        ///     
  28.        public override void ItemDeleted(SPItemEventProperties properties)    
  29.        {    
  30.            string ID1 = ID;    
  31.           int IDConverted = Convert.ToInt32(ID1);    
  32.            SPSite ListSite = new SPSite(properties.Web.Url);    
  33.            SPWeb ListWeb = ListSite.OpenWeb();    
  34.            SPQuery query = new SPQuery();    
  35.            query.Query = "" +    
  36.                         "" +    
  37.                             "" +    
  38.                             "ID1Converted" +    
  39.                         "" +    
  40.                     "";    
  41.            SPListItem KarnetItem = ListWeb.Lists["Karnet"].GetItems(query)[0];    
  42.            KarnetItem.Delete();    
  43.     
  44.            base.ItemDeleted(properties);    
  45.        }    
  46.     
  47.     
  48.     }    
  49. }   
i tryed that assign value item id to variable ID in ItemDeleting. next this variable i use for filtering second list query.Query, then selected item i delete with KarnetList.Delete(); , but nothing.

I noticed that my code deletes an item from calendar view of the second list, but not from all items view. why?

Some guide for my help?

 

Answers (1)