Get outlook profile name programatically

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

Get outlook profile name programatically
 
Manoj Jha




Posts: 2
Joined: 2009-11-10
I'm trying to figure out how to programatically get the string name of the current outlook profile Name from within a C# Add-in-express addin.

Using Outlook spy I am able to find its under Application - Session - CurrentProfileName .But how to implement it using addin express
Posted 10 Nov, 2009 03:35:51 Top
Andrei Smolin


Add-in Express team


Posts: 19011
Joined: 2006-05-11
Hello Manoj,

You can use the OutlookProfileName property of the add-in module; it was introduced in version 5.2 of Add-in Express. Also, you can use Namespace.CurrentProfileName in Outlook 2007. Since you don't see it, I suppose you use version-neutral interops, which, in case of Outlook, are interops for Outlook 2000. To bypass this, you can use late binding (see System.Type.InvokeMember).


Andrei Smolin
Add-in Express Team Leader
Posted 10 Nov, 2009 03:56:06 Top
Manoj Jha




Posts: 2
Joined: 2009-11-10
Thanks for your feedback.I am able to get Current Profile Name using System.Type.InvokeMember

Code snippet is as below:

Outlook.NameSpace objNS = null;
Outlook.Application objApplication = null;
try
{

objApplication = new Outlook.Application();
objNS = objApplication.GetNamespace("MAPI");
Object CurrentProfileName = objNS.GetType().InvokeMember("CurrentProfileName", System.Reflection.BindingFlags.GetProperty, null, objNS, null);
String strCurrentProfileName = CurrentProfileName.ToString();
MessageBox.Show(strCurrentProfileName,"Current Profile Name");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
if (objNS != null)
Marshal.ReleaseComObject(objNS);
if (objApplication != null)
Marshal.ReleaseComObject(objApplication);
} :D
Posted 10 Nov, 2009 05:16:14 Top
Andrei Smolin


Add-in Express team


Posts: 19011
Joined: 2006-05-11
Manoj,

Instead of creating a new Outlook.Application, you need to use the OutlookApp property of the add-in module. The use of an Outlook.Application created in this way will produce security warnings when accessing certain properties or methods on a PC that doesn't have a properly updated antivirus software.

Also, I'd check Outlook version instead of using try/catch but this is a matter of taste.


Andrei Smolin
Add-in Express Team Leader
Posted 10 Nov, 2009 08:59:56 Top