Closed dp250195 closed 2 years ago
Does this solution help? https://stackoverflow.com/questions/41387975/netoffice-outlook-add-in-access-folder-events
Does this solution help? https://stackoverflow.com/questions/41387975/netoffice-outlook-add-in-access-folder-events
Unfortunately, this does not help.
I can see the event being declared here: https://github.com/NetOfficeFw/NetOffice/blob/main/Source/Outlook/Events/ItemsEvents.cs#L22 but I can't find a way to reference it in my code. I'm not making an AddIn though, I'm making a Windows Service app, I added the NuGet packages myself and I did not use this Toolbox being mentioned.
I found the solution. I had to typecast everything to appropriate class (like Outlook._Items
to Outlook.Items
), and now I can see the ItemAddEvent
.
UPDATE: Adding code for reference
using Outlook = NetOffice.OutlookApi;
public class MailService
{
// Local fields
private Outlook.Application oApp;
private Outlook.Explorer oExplorer;
private Outlook.NameSpace oNS;
private Outlook.MAPIFolder oInbox;
private Outlook.Items oInboxItems;
// ctor
public MailService()
{
oApp = new Outlook.Application();
oExplorer = (Outlook.Explorer)oApp.ActiveExplorer();
oNS = (Outlook.NameSpace)oApp.GetNamespace("MAPI");
oInbox = oNS.Folders["MyEMail@company.com"].Folders["Inbox"];
oInboxItems = (Outlook.Items)oInbox.Items;
oInboxItems.ItemAddEvent += OInboxItems_ItemAddEvent;
}
private void OInboxItems_ItemAddEvent(NetOffice.ICOMObject item)
{
// Code to handle ItemAdd event
}
}
I can't find a way to attach an event handler to
Outlook.Items.ItemAdd
. Visual Studio IntelliSense doesn't show any event handlers available forOutlook.Items
. I've gone through all available examples, but I can't find any that illustrate use of event handlers. I tried addingusing NetOffice.OutlookApi.Events
, but this doesn't seem to add anything. Searching the entire Internet did not provide any useful answers.