Accessing folder attributes from property page in folder properties dialog in Outlook

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

Accessing folder attributes from property page in folder properties dialog in Outlook
 
mgarber




Posts: 14
Joined: 2010-06-22
Hello,
A while back I created this thread http://www.add-in-express.com/forum/read.php?FID=5&TID=7512. Now that I need to go back to that and found some issues it looks like the thread is closed, so I'll create a new one.

1) It seems like OutlookApp.ActiveExplorer().CurrentFolder isn't the correct answer. If I have Sent Items open in the explorer, then I right-click Inbox and select properties, OutlookApp.ActiveExplorer().CurrentFolder will be Sent Items. I need some way to know that the folder I right-clicked is Inbox.

EDIT: for #1 I found that I could save a reference to the folder given by the NamespaceBeforeOptionPageAdd Outlook Event. Onto #2, then.

2) I managed to use InvokeMember to get the user properties like this:
folder.GetType().InvokeMember("UserDefinedProperties", System.Reflection.BindingFlags.GetProperty, null, folder, null);
The problem is that it returns a System.__ComObject, and I don't have the UserDefinedProperties class to be able to go through them. I tried with UserProperties, but it didn't work.

What can I do?
---
Technical information:
Add-in Express 2010 for Office and .NET
Outlook 2007 / Outlook 2003
VS2008 SP1
WinXP SP2
Posted 20 Sep, 2010 16:08:28 Top
Eugene Astafiev


Add-in Express team


Posts: 8540
Joined: 2007-07-25
Hi Matias,

You can use the late binding technology (see the System.Type.InvokeMember method) in case of Outlook 2007 and 2010. Please be aware this property/class doesn't exist in earlier versions of Outlook.
.NET, Extended MAPI, Windows Phone & RT
Posted 21 Sep, 2010 04:01:49 Top
mgarber




Posts: 14
Joined: 2010-06-22
Yes, I know. As I said, I already AM using the late binding technology. The problem is that I don't have the class for the object it returns (UserDefinedProperties). This is probably because this project is set up to be able to be used on every Outlook version, and UserDefinedProperties is specific for 2007/2010, I know, but is there any way I can get it without changing that (without using late binding for EVERYTHING, which would be too slow)?
---
Technical information:
Add-in Express 2010 for Office and .NET
Outlook 2007 / Outlook 2003
VS2008 SP1
WinXP SP2
Posted 21 Sep, 2010 10:23:58 Top
Andrei Smolin


Add-in Express team


Posts: 14094
Joined: 2006-05-11
Hi Matias,

You can add the Outlook 2007 interop to your project and develop/debug your code using early binding. Then you can remove the Outlook 2007 interop and convert your code to use late binding; this step is optional.

Regards from Belarus (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 21 Sep, 2010 10:48:29 Top
mgarber




Posts: 14
Joined: 2010-06-22
Yes, but that would mean using late binding all the time, that's too slow. I found a better way: I created a new VSTO project, copied the path to the interop dll (C:\Program Files\Microsoft Visual Studio 9.0\Visual Studio Tools for Office\PIA\Office12\Microsoft.Office.Interop.Outlook.dll) and added a reference to it in my ADX project, works like a charm. Basically:

using Outlook2007 = Microsoft.Office.Interop.Outlook;
[...]
if (AddinModule.CurrentInstance.HostVersion.StartsWith("12."))
{
Outlook2007.Folder _2007Folder = (Outlook2007.Folder)_ADXFolder;
var _UserProperty = _2007Folder.UserDefinedProperties["CustomProperty01"];
}

That way I don't have to use late binding.
---
Technical information:
Add-in Express 2010 for Office and .NET
Outlook 2007 / Outlook 2003
VS2008 SP1
WinXP SP2
Posted 21 Sep, 2010 12:48:03 Top
Eugene Astafiev


Add-in Express team


Posts: 8540
Joined: 2007-07-25
Hi Matias,

Thank you for letting us know.

However, please be aware that you can find the required interop assemblies for Office 2007 in the following folder on your PC:

[Add-in Express installation folder]Add-in Express for .NETRedistributablesInterop AssembliesOffice 2007
.NET, Extended MAPI, Windows Phone & RT
Posted 22 Sep, 2010 05:07:49 Top
mgarber




Posts: 14
Joined: 2010-06-22
Actually, I have no "Office 2007" folder in "Add-in Express for .NET\Redistributables\Interop Assemblies".
---
Technical information:
Add-in Express 2010 for Office and .NET
Outlook 2007 / Outlook 2003
VS2008 SP1
WinXP SP2
Posted 22 Sep, 2010 10:24:19 Top
Eugene Astafiev


Add-in Express team


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

Please make sure that you use the latest build of Add-in Express.
.NET, Extended MAPI, Windows Phone & RT
Posted 22 Sep, 2010 11:52:48 Top