How to get calendar owner for an appointment

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

How to get calendar owner for an appointment
 
Kelvin Box




Posts: 77
Joined: 2009-08-30

In outlook if I have another users calendar displayed and I create a new appointment for that user, I need to be able to determine who that particular user is from within my code.

Is there a way to do this?

I basically want to know who the owner is for the appointment I have just created.

Cheers

Kelvin
Posted 14 Sep, 2009 22:42:11 Top
Andrei Smolin


Add-in Express team


Posts: 18842
Joined: 2006-05-11
Hello Kelvin,

I've found an interesting link for you: http://www.eggheadcafe.com/conversation.aspx?messageid=31691555&threadid=31691553. In those conversation, besides getting a [relatively] simple answer to your question, you'll find two titans of Outlook programming revealing a fine aspect of determining the owner of a mailbox. Wow! It's like touching something that only elected are able to touch :)

Sorry. Back to your question.

If you use pre-2007 Outlook, you can use our free MAPI Store Accessor (see Products | Free Stuff in the main menu above) to get the properties mentioned by Ken Slovak. This tool wraps Extended MAPI in order to provide it to .NET developers (contrary to what Ken says).

Please let me know whether this helps.


Andrei Smolin
Add-in Express Team Leader
Posted 15 Sep, 2009 03:35:38 Top
Kelvin Box




Posts: 77
Joined: 2009-08-30
Thanks for the reply.

When I add the MAPI Store Accessor to my project the add-in stops working i.e. the command bar isn't displayed and the add-in form doesn't show for any appointments.

Is there a trick to get it to work?

Cheers
Posted 15 Sep, 2009 15:47:29 Top
Kelvin Box




Posts: 77
Joined: 2009-08-30
Not sure if it matters but I'm using Outlook 2003 with VS2008
Posted 15 Sep, 2009 15:54:09 Top
Kelvin Box




Posts: 77
Joined: 2009-08-30
After some more testing I now get this error.

Exception Source: AddinExpress.MAPI
Exception Type: System.DllNotFoundException
Exception Message: Unable to load DLL 'MSVCR80.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
Exception Target Site: _encode_pointer
Object reference not set to an instance of an object.


I tried downloading a copy of the dll it mentions but that just gives me more errors when I run my application


Managed Debugging Assistant 'LoaderLock' has detected a problem in 'C:\Program Files\Microsoft Office\OFFICE11\OUTLOOK.EXE'.
Additional Information: Attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang.
Posted 16 Sep, 2009 00:22:07 Top
Andrei Smolin


Add-in Express team


Posts: 18842
Joined: 2006-05-11
Hello Kelvin,

MSVCR80.dll. Please read "12. How can I deploy my add-ins /applications?" at http://www.add-in-express.com/products/mapi-store-events.php.

Loader Lock. You can clear the corresponding check box in Debug | Exceptions | Managed Debugging Assistants (see the main menu in VS 2005-2008).

...the add-in stops working i.e. the command bar isn't displayed...


The checklist for such a scenario is http://www.add-in-express.com/docs/net-commandbar-tips.php#dont-show.

Can you please keep me informed about your progress?


Andrei Smolin
Add-in Express Team Leader
Posted 16 Sep, 2009 03:26:01 Top
Kelvin Box




Posts: 77
Joined: 2009-08-30
I have installed the VC++ runtime library and it doesn't seem to have made any difference.

I cleared the Loader Lock item in debug and no longer get that error but I still get the error saying MSVCR80.dll is missing.

I'm off to bed now as it's midnight but will have another attempt in the morning. If you can think of anything else that may help with this error then it would be much appreciated.


Cheers
Kelvin
Posted 16 Sep, 2009 06:49:57 Top
Andrei Smolin


Add-in Express team


Posts: 18842
Joined: 2006-05-11
Kelvin,

Please make sure that you install Visual C++ Runtime Libraries (x86) SP1.

I've got the following code that works fine for me in Outlook 2007.

private void AddinModule_AddinInitialize(object sender, EventArgs e)
{
    adxmapiStoreAccessor1.Initialize(false);
}

private void AddinModule_AddinBeginShutdown(object sender, EventArgs e)
{
    adxmapiStoreAccessor1.LogOff();
}

private void adxCommandBarButton1_Click(object sender)
{
    Outlook.Explorer explorer = OutlookApp.ActiveExplorer();
    Outlook.MAPIFolder folder = explorer.CurrentFolder;
    for (int i = 0; i < adxmapiStoreAccessor1.MsgStores.Count; i++)
    {
        if (adxmapiStoreAccessor1.MsgStores[i].EntryId.ToString().ToLower() == folder.StoreID.ToLower())
        {
            object isStoreOffline = adxmapiStoreAccessor1.MsgStores[i].GetProperty(AddinExpress.MAPI.ADXMAPIPropertyTag._PR_STORE_OFFLINE);
            if (isStoreOffline == null) //there's no PR_STORE_OFFLINE tag
            {
                // PST
                object storeDisplayName = adxmapiStoreAccessor1.MsgStores[i].GetProperty(AddinExpress.MAPI.ADXMAPIPropertyTag._PR_DISPLAY_NAME);
                System.Windows.Forms.MessageBox.Show("PST. Store display name: " + storeDisplayName.ToString());
            }
            else
                if ((bool)isStoreOffline)
                {
                    // cached Exchange mode
                    object storeDisplayName = adxmapiStoreAccessor1.MsgStores[i].GetProperty(AddinExpress.MAPI.ADXMAPIPropertyTag._PR_DISPLAY_NAME);
                    System.Windows.Forms.MessageBox.Show("Cached Exchange mode. Store display name: " + storeDisplayName.ToString());
                }
                else
                {
                    // non-cached Exchange mode
                    object userName = adxmapiStoreAccessor1.MsgStores[i].GetProperty(AddinExpress.MAPI.ADXMAPIPropertyTag._PR_MAILBOX_OWNER_NAME);
                    System.Windows.Forms.MessageBox.Show("Non-cached Exchange mode. Mailbox owner name: " + userName.ToString());
                }
        }
    }
    Marshal.ReleaseComObject(folder);
    Marshal.ReleaseComObject(explorer);
}
}



Andrei Smolin
Add-in Express Team Leader
Posted 17 Sep, 2009 04:45:46 Top
Kelvin Box




Posts: 77
Joined: 2009-08-30
Thank-you for the code! Thats awesome!

What changes would need to be made for it to work in Outlook 2003?


I have installed the C++ runtime libraries and can get the MAPI store accessor object to work from a normal application but not from within the add-in...haven't quite figured out why yet but making some progress!
Posted 17 Sep, 2009 05:10:55 Top
Andrei Smolin


Add-in Express team


Posts: 18842
Joined: 2006-05-11
Kelvin,

The code above doesn't depend on Outlook version that you use. Not sure, however, if all the tags used in the code are available in all Outlook/Exchange versions. I've installed this test add-in on Windows XP SP 3 + Outlook 2003 SP 3. It works with no problems.

Do you have VS 2008 SP1 installed? It contains Visual C++ Runtime Libraries (x86) SP1, to my knowledge.

Hope this helps.


Andrei Smolin
Add-in Express Team Leader
Posted 17 Sep, 2009 08:09:24 Top