Using Outlook 2003/2007 PIA's in standalone application



I have written a standalone C# program which has used the Office/Outlook XP
PIA's to access the Outlook Object Model, Word Object Model, etc. I link
directly to the dll's which come in the PIA "kit", which is probably
non-standard, but allows my standalone app to run even if Microsoft Office
is not installed. I conditionalize my Office-related code by checking
registry entries to determine if various Office applications are installed.
This basically works.

However, I would like to start using the Office 2003 PIA's and link properly
to them via the GAC. These are not just a collection of PIA's and .reg
files, but are instead an installer which requires Microsoft Office to be
installed. This would make my application require Microsoft Office, which
is not acceptable.

Is there any way to build and distribute a C# application that can use the
Microsoft Office object models when present, but also run without problems
when Office is not installed? I have heard about late-binding, but don't
know much about it... is that a possible solution? The examples I have seen
make it seem difficult. Thanks in advance for the help.




Ken Slovak - [MVP - Outlook]

Late binding is actually what you're using now if you're using the Interop.
That's why you have to cast objects received from the Interop to the various
types exposed in the object models.

For true late binding you treat everything as an object and only access
properties using methods such as this:

oWhatever.GetType().InvokeMember("Subject", BindingFlags.Public |
BindingFlags.SetProperty, null, oWhatever, new object[] { "Test"});

That would set the Subject to "Test". After that of course you'd have to
save the item.

When you use late binding you also can't handle any object events.

Using the PIA's without Office or Outlook installed isn't really a good way
to go and may be a license breaker. That you'd have to take up with MS.

What I'd probably do is compile all my Office/Outlook related code into a
DLL and only load that if the applications were installed. I'd check in my
main code to see if they are installed, probably by reading the registry to
get the installation paths of any applications I wanted to use, and load or
not load the DLL as appropriate.

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question