Question about MAPI Store Accessor Sample

Add-in Express™ Support Service
That's what is more important than anything else

Question about MAPI Store Accessor Sample
 
Zing




Posts: 35
Joined: 2010-02-24
Hi Forum,

I downloaded your MAPI Store Accessor sample from here http://www.add-in-express.com/creating-addins-blog/2009/05/15/outlook-itemadd-event/

and I wonder about the line
if (e.ParentId.ToString() == AddinExpress.MAPI.EntryId.ConvertToString(folderId as byte[]))

in adxmapiStoreAccessor_OnObjectCreated when copying an E-Mail. This line appears to never match so acutally this sample never logs the "AddEventToLog(..." message?!
ProcessItemAdd works (if one can speak of "working" with this method..), but is not sufficient.

What can I do to make your sample work with new/copied/moved MailItems?

Thank you for your help!

Regards,
Zing
Posted 26 Jul, 2010 10:42:49 Top
Zing




Posts: 35
Joined: 2010-02-24
Nobody has any thoughts/tipps on this? Andrei? Eugene?
Posted 27 Jul, 2010 06:22:06 Top
Eugene Astafiev


Add-in Express team


Posts: 8540
Joined: 2007-07-25
Hello Moritz,

I have just tested a sample project developed by Dmitry Kostochko.

It works only if you connect to the Drafts folder. By default in Outlook all newly created emails will be placed in the Drafts folder (not Inbox). Say, the line of code will be reached if you reconnect to the Drafts folder.

The MAPI Store Accessor works like a charm ;-)
.NET, Extended MAPI, Windows Phone & RT
Posted 27 Jul, 2010 07:47:21 Top
Zing




Posts: 35
Joined: 2010-02-24
Hi Eugene,

args.. my reply was lost because of an incorrect captcha code!? I didn't see any captcha here, so I hope replying works this time..

I tested it with Drafts folder and new mails that got created by Autosave as well as existing mails that I copied into that folder but still e.ParentId != folderId.
Even in Inbox with new mails that I received the IDs never matched..
I'm confused....
Posted 27 Jul, 2010 09:55:21 Top
Eugene Astafiev


Add-in Express team


Posts: 8540
Joined: 2007-07-25
Hello Moritz,

May I see the issue? Could you share your desktop to me?
.NET, Extended MAPI, Windows Phone & RT
Posted 28 Jul, 2010 03:52:57 Top
Zing




Posts: 35
Joined: 2010-02-24
Sure!
How can I reach you?
I've two easy ways to share my screen.
Posted 28 Jul, 2010 03:55:25 Top
Zing




Posts: 35
Joined: 2010-02-24
Eugene, I found out that the problem only exists if Outlook is not in cached mode...
The IDs are different if cached mode is disabled.
Do you see a chance to make this event work with both Outlook modes?
Posted 28 Jul, 2010 05:14:39 Top
Eugene Astafiev


Add-in Express team


Posts: 8540
Joined: 2007-07-25
Moritz,

I have reproduced the issue. Thank you for the detailed info.

Entry IDs differ in Outlook and Exteneded MAPI in case of non-cached exchange mode. In a sample add-in I have used the following workaround:

private void adxmapiStoreAccessor_OnObjectCreated(object sender, AddinExpress.MAPI.ADXMAPIObjectNotificationEventArgs e)
		{
            string name = null;
            AddinExpress.MAPI.Folder fld = adxmapiStoreAccessor.GetMapiFolder(e.ParentId);
            try
            {
                name = (string)fld.GetProperty(AddinExpress.MAPI.ADXMAPIPropertyTag._PR_DISPLAY_NAME);
            }
            finally
            {
                fld.Dispose();
            }
            Outlook.MAPIFolder outklookFolder = itemsEvents.FolderObj as Outlook.MAPIFolder;
			if (outklookFolder != null )
			{	
				if (outklookFolder.Name == name)
				{   
				    AddinExpress.MAPI.MapiItem item = adxmapiStoreAccessor.GetMapiItem(e.EntryId);
                    if (item != null)
                    {
                        string subject = (string)item.GetProperty(AddinExpress.MAPI.ADXMAPIPropertyTag._PR_SUBJECT);
                        try
                        {
                            AddEventToLog(" Object created. Subject = " + subject);
                        }
                        finally
                        {
                            item.Dispose();
                        }
                    }						
				}
			}
		}


Please let me know whether it works for you.
.NET, Extended MAPI, Windows Phone & RT
Posted 28 Jul, 2010 07:23:03 Top
Zing




Posts: 35
Joined: 2010-02-24
Thanks for that answer, I'll test that soon!

I think I have a further question about the Store Accessor that I want to ask, before running the tests.

As I saw it so far, you can only connect the ItemsEvents to one folder but with a recursive option for the sub folders beneath. If I understood that right this means that the corresponding events are only fired for the folder to which the events are connected, right?!
In my tests the events are fired for the connected folder but also for the inbox every time!? Is this correct?

The next question is, how can I connect the events to more than just one folder because I want to monitor multiple folders on various “levels” without recursive in the store. I tried creating multiple ItemsEvents objects in a list and connecting one folder per itemsEvents but it looks like this causes that no events are fired at all (except inbox again).

Also I wonder why the OnObjectMoved and OnObjectCopied events are fired, even though they were not enabled in SupportedStoreEvents?!

Can you tell me your thoughts about this?
Posted 28 Jul, 2010 08:22:10 Top
Zing




Posts: 35
Joined: 2010-02-24
your work around above works with disabled cached mode. The "disadvantage" is that the whole procedure now depends on the folder name instead of its ID, so basically this work around is triggered for each folder with the same name.

I’m not sure what to think about this because working with the IDs would be safer (and the cached mode is recommended by Microsoft anyway) so…
Maybe I find a way to check whether the cached mode is disabled and show a warning…
Anyway thanks for your help regarding that work around, I will use it for now to have an implementation that works.

If you have any ideas about my other questions I’d be happy about that ;-)

Regards,
-Moritz
Posted 28 Jul, 2010 10:15:54 Top