none
Catch an event when/before an Item was deleted RRS feed

  • Question

  • Hello,

    i tried to ask this question on Stackoverflow - with no results. 

    For my Outlook Add-in I want to get an Event when an Appointment was deleted. 

    the problem is, when I apply my handler to the Folder.BeforeDeleted event, it just get fired, when the Folder was created some lines before, not when I get the Folder from Office (because it was created a week ago).

    Thanks for Your help!

    Monday, August 6, 2012 10:51 AM

Answers

  • I don't understand this part of your code. It appears that you are attempting to cast a Folder (or MAPIFolder) as a Folder event:
     
        _CalendarFolder = _CalendarMAPIFolder as Outlook.MAPIFolderEvents_12_Event;
       
    if (_CalendarFolder == null)
       
    {
           
    MessageBox.Show("can not cast MAPIFolder to Folder");
       
    }


        _CalendarFolder
    .BeforeItemMove += new Outlook.MAPIFolderEvents_12_BeforeItemMoveEventHandler(Folder_BeforeItemMove);
     
    _CalendarFolder should be a Folder, not a folder event. And why are you using MAPIFolder at all there, why not just use Folder directly if you are using Outlook 2007 or higher?

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Xaw4" <=?utf-8?B?WGF3NA==?=> wrote in message news:eb645a59-ffb1-4aa6-8a20-80924db55bdd...

    Yes i did!

    my code looks like this:

    Outlook.MAPIFolder calendarFolder =
           
    this.Application.GetNamespace("mapi").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);

       
    // get my-Folder (if not found, create it)
       
    try
       
    {
            _CalendarMAPIFolder
    = calendarFolder.Folders["my-Folder"];
       
    }
       
    catch
       
    {
            _CalendarMAPIFolder
    = calendarFolder.Folders.Add("my-Folder");
       
    }
        _CalendarItems
    = _CalendarMAPIFolder.Items;
        _CalendarFolder
    = _CalendarMAPIFolder as Outlook.MAPIFolderEvents_12_Event;
       
    if (_CalendarFolder == null)
       
    {
           
    MessageBox.Show("can not cast MAPIFolder to Folder");
       
    }


        _CalendarFolder
    .BeforeItemMove += new Outlook.MAPIFolderEvents_12_BeforeItemMoveEventHandler(Folder_BeforeItemMove);

    the event only fires, if i created ( Folders.Add(...) ) the folder, not when i get ( Folders[..] ) it.


    Ken Slovak MVP - Outlook
    Monday, August 6, 2012 3:21 PM
    Moderator

All replies

  • Monday, August 6, 2012 11:07 AM
  • Yes i did!

    my code looks like this:

    Outlook.MAPIFolder calendarFolder =
           
    this.Application.GetNamespace("mapi").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);

       
    // get my-Folder (if not found, create it)
       
    try
       
    {
            _CalendarMAPIFolder
    = calendarFolder.Folders["my-Folder"];
       
    }
       
    catch
       
    {
            _CalendarMAPIFolder
    = calendarFolder.Folders.Add("my-Folder");
       
    }
        _CalendarItems
    = _CalendarMAPIFolder.Items;
        _CalendarFolder
    = _CalendarMAPIFolder as Outlook.MAPIFolderEvents_12_Event;
       
    if (_CalendarFolder == null)
       
    {
           
    MessageBox.Show("can not cast MAPIFolder to Folder");
       
    }


        _CalendarFolder
    .BeforeItemMove += new Outlook.MAPIFolderEvents_12_BeforeItemMoveEventHandler(Folder_BeforeItemMove);

    the event only fires, if i created ( Folders.Add(...) ) the folder, not when i get ( Folders[..] ) it.

    Monday, August 6, 2012 11:21 AM
  • please verify that you have latest patches for your outlook. Also you might look at this: http://support.microsoft.com/kb/971367/en-us 
    Monday, August 6, 2012 11:57 AM
  • I don't understand this part of your code. It appears that you are attempting to cast a Folder (or MAPIFolder) as a Folder event:
     
        _CalendarFolder = _CalendarMAPIFolder as Outlook.MAPIFolderEvents_12_Event;
       
    if (_CalendarFolder == null)
       
    {
           
    MessageBox.Show("can not cast MAPIFolder to Folder");
       
    }


        _CalendarFolder
    .BeforeItemMove += new Outlook.MAPIFolderEvents_12_BeforeItemMoveEventHandler(Folder_BeforeItemMove);
     
    _CalendarFolder should be a Folder, not a folder event. And why are you using MAPIFolder at all there, why not just use Folder directly if you are using Outlook 2007 or higher?

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Xaw4" <=?utf-8?B?WGF3NA==?=> wrote in message news:eb645a59-ffb1-4aa6-8a20-80924db55bdd...

    Yes i did!

    my code looks like this:

    Outlook.MAPIFolder calendarFolder =
           
    this.Application.GetNamespace("mapi").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);

       
    // get my-Folder (if not found, create it)
       
    try
       
    {
            _CalendarMAPIFolder
    = calendarFolder.Folders["my-Folder"];
       
    }
       
    catch
       
    {
            _CalendarMAPIFolder
    = calendarFolder.Folders.Add("my-Folder");
       
    }
        _CalendarItems
    = _CalendarMAPIFolder.Items;
        _CalendarFolder
    = _CalendarMAPIFolder as Outlook.MAPIFolderEvents_12_Event;
       
    if (_CalendarFolder == null)
       
    {
           
    MessageBox.Show("can not cast MAPIFolder to Folder");
       
    }


        _CalendarFolder
    .BeforeItemMove += new Outlook.MAPIFolderEvents_12_BeforeItemMoveEventHandler(Folder_BeforeItemMove);

    the event only fires, if i created ( Folders.Add(...) ) the folder, not when i get ( Folders[..] ) it.


    Ken Slovak MVP - Outlook
    Monday, August 6, 2012 3:18 PM
    Moderator
  • I don't understand this part of your code. It appears that you are attempting to cast a Folder (or MAPIFolder) as a Folder event:
     
        _CalendarFolder = _CalendarMAPIFolder as Outlook.MAPIFolderEvents_12_Event;
       
    if (_CalendarFolder == null)
       
    {
           
    MessageBox.Show("can not cast MAPIFolder to Folder");
       
    }


        _CalendarFolder
    .BeforeItemMove += new Outlook.MAPIFolderEvents_12_BeforeItemMoveEventHandler(Folder_BeforeItemMove);
     
    _CalendarFolder should be a Folder, not a folder event. And why are you using MAPIFolder at all there, why not just use Folder directly if you are using Outlook 2007 or higher?

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Xaw4" <=?utf-8?B?WGF3NA==?=> wrote in message news:eb645a59-ffb1-4aa6-8a20-80924db55bdd...

    Yes i did!

    my code looks like this:

    Outlook.MAPIFolder calendarFolder =
           
    this.Application.GetNamespace("mapi").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);

       
    // get my-Folder (if not found, create it)
       
    try
       
    {
            _CalendarMAPIFolder
    = calendarFolder.Folders["my-Folder"];
       
    }
       
    catch
       
    {
            _CalendarMAPIFolder
    = calendarFolder.Folders.Add("my-Folder");
       
    }
        _CalendarItems
    = _CalendarMAPIFolder.Items;
        _CalendarFolder
    = _CalendarMAPIFolder as Outlook.MAPIFolderEvents_12_Event;
       
    if (_CalendarFolder == null)
       
    {
           
    MessageBox.Show("can not cast MAPIFolder to Folder");
       
    }


        _CalendarFolder
    .BeforeItemMove += new Outlook.MAPIFolderEvents_12_BeforeItemMoveEventHandler(Folder_BeforeItemMove);

    the event only fires, if i created ( Folders.Add(...) ) the folder, not when i get ( Folders[..] ) it.


    Ken Slovak MVP - Outlook
    Monday, August 6, 2012 3:21 PM
    Moderator