Late Binding Outlook

  • Thread starter Thread starter John Smith
  • Start date Start date
J

John Smith

Hey,

I'm having a difficult time finding some good examples of late binding
Outlook in C#. Anyone know of any good sites out there? I've googled and
MSDN'ed, but have come up a bit empty.

IT MUST BE LATE-BINDING THOUGH.

I need to be able to open an existing contact folder or create a new contact
folder, and add new contacts to it.

Thanks!
 
John,

Are you having problems with using reflection, or just the object model
of outlook? If it is the latter, then check out the article on MSDN titled
"Automating Outlook from a Visual Basic Applications", located at (watch for
line wrap):

http://msdn.microsoft.com/library/d...tomatingOutlookFromVisualBasicApplication.asp

It will give you a basic idea of the object model, and should lead you
to more detailed references.

If you are looking for a reference on reflection, then check out the
section of the .NET Framework developers guide titled "Reflection Overview",
located at (watch for line wrap):

http://msdn.microsoft.com/library/d...n-us/cpguide/html/cpconReflectionOverview.asp

Hope this helps.
 
Thanks Nicholas .

I guess I'm more just looking for examples because the way that I expect
things to work, currently is not. For instance, the below fails on the
fourth line (while trying to get the default folder) with an unspecified
exception. I'm sure the mistake is small, but some examples sure would
speed up my debugging:
Type oType = Type.GetTypeFromProgID("Outlook.Application");

Object oApp = Activator.CreateInstance(oType);

Object oNameSpace = oApp.GetType().InvokeMember("GetNamespace",
BindingFlags.GetProperty, null, oApp, new object[1]{"MAPI"});

Object oFolder = oNameSpace.GetType().InvokeMember("GetDefaultFolder",
BindingFlags.GetProperty, null, oNameSpace, null);

Object oAllFolders = oFolder.GetType().InvokeMember("Folders",
BindingFlags.GetProperty, null, oFolder, null);

Object oCurFolder = oAllFolders.GetType().InvokeMember("Add",
BindingFlags.InvokeMethod, null, oAllFolders, new object[1]{"folderName"});



Nicholas Paldino said:
John,

Are you having problems with using reflection, or just the object model
of outlook? If it is the latter, then check out the article on MSDN titled
"Automating Outlook from a Visual Basic Applications", located at (watch for
line wrap):

http://msdn.microsoft.com/library/d...tomatingOutlookFromVisualBasicApplication.asp

It will give you a basic idea of the object model, and should lead you
to more detailed references.

If you are looking for a reference on reflection, then check out the
section of the .NET Framework developers guide titled "Reflection Overview",
located at (watch for line wrap):

http://msdn.microsoft.com/library/d...n-us/cpguide/html/cpconReflectionOverview.asp

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

John Smith said:
Hey,

I'm having a difficult time finding some good examples of late binding
Outlook in C#. Anyone know of any good sites out there? I've googled and
MSDN'ed, but have come up a bit empty.

IT MUST BE LATE-BINDING THOUGH.

I need to be able to open an existing contact folder or create a new
contact
folder, and add new contacts to it.

Thanks!
 
The problem with that line by the way is that I'm not passing it the folder
type (in this case contacts...Outlook.OlDefaultFolders.olFolderContacts),
but I don't know what constant I should use for that.



John Smith said:
Thanks Nicholas .

I guess I'm more just looking for examples because the way that I expect
things to work, currently is not. For instance, the below fails on the
fourth line (while trying to get the default folder) with an unspecified
exception. I'm sure the mistake is small, but some examples sure would
speed up my debugging:
Type oType = Type.GetTypeFromProgID("Outlook.Application");

Object oApp = Activator.CreateInstance(oType);

Object oNameSpace = oApp.GetType().InvokeMember("GetNamespace",
BindingFlags.GetProperty, null, oApp, new object[1]{"MAPI"});

Object oFolder = oNameSpace.GetType().InvokeMember("GetDefaultFolder",
BindingFlags.GetProperty, null, oNameSpace, null);

Object oAllFolders = oFolder.GetType().InvokeMember("Folders",
BindingFlags.GetProperty, null, oFolder, null);

Object oCurFolder = oAllFolders.GetType().InvokeMember("Add",
BindingFlags.InvokeMethod, null, oAllFolders, new object[1]{"folderName"});



message news:#[email protected]...
John,

Are you having problems with using reflection, or just the object model
of outlook? If it is the latter, then check out the article on MSDN titled
"Automating Outlook from a Visual Basic Applications", located at (watch for
line wrap):
http://msdn.microsoft.com/library/d...tomatingOutlookFromVisualBasicApplication.asp
It will give you a basic idea of the object model, and should lead you
to more detailed references.

If you are looking for a reference on reflection, then check out the
section of the .NET Framework developers guide titled "Reflection Overview",
located at (watch for line wrap):
http://msdn.microsoft.com/library/d...n-us/cpguide/html/cpconReflectionOverview.asp
Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

John Smith said:
Hey,

I'm having a difficult time finding some good examples of late binding
Outlook in C#. Anyone know of any good sites out there? I've googled and
MSDN'ed, but have come up a bit empty.

IT MUST BE LATE-BINDING THOUGH.

I need to be able to open an existing contact folder or create a new
contact
folder, and add new contacts to it.

Thanks!
 
Guess it's 10.


John Smith said:
The problem with that line by the way is that I'm not passing it the folder
type (in this case contacts...Outlook.OlDefaultFolders.olFolderContacts),
but I don't know what constant I should use for that.



John Smith said:
Thanks Nicholas .

I guess I'm more just looking for examples because the way that I expect
things to work, currently is not. For instance, the below fails on the
fourth line (while trying to get the default folder) with an unspecified
exception. I'm sure the mistake is small, but some examples sure would
speed up my debugging:
Type oType = Type.GetTypeFromProgID("Outlook.Application");

Object oApp = Activator.CreateInstance(oType);

Object oNameSpace = oApp.GetType().InvokeMember("GetNamespace",
BindingFlags.GetProperty, null, oApp, new object[1]{"MAPI"});

Object oFolder = oNameSpace.GetType().InvokeMember("GetDefaultFolder",
BindingFlags.GetProperty, null, oNameSpace, null);

Object oAllFolders = oFolder.GetType().InvokeMember("Folders",
BindingFlags.GetProperty, null, oFolder, null);

Object oCurFolder = oAllFolders.GetType().InvokeMember("Add",
BindingFlags.InvokeMethod, null, oAllFolders, new object[1]{"folderName"});



message news:#[email protected]...
John,

Are you having problems with using reflection, or just the object model
of outlook? If it is the latter, then check out the article on MSDN titled
"Automating Outlook from a Visual Basic Applications", located at
(watch
for
line wrap):
http://msdn.microsoft.com/library/d...n-us/cpguide/html/cpconReflectionOverview.asp
Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hey,

I'm having a difficult time finding some good examples of late binding
Outlook in C#. Anyone know of any good sites out there? I've
googled
and
MSDN'ed, but have come up a bit empty.

IT MUST BE LATE-BINDING THOUGH.

I need to be able to open an existing contact folder or create a new
contact
folder, and add new contacts to it.

Thanks!
 
John Smith said:
Hey,

IT MUST BE LATE-BINDING THOUGH.

Why?
Late-binding was invented to accommodate scripting languages, it has no
benefits only drawbacks, just currious.

Willy.
 
Contacts default folder = 5, Consult the CDO 1.2.1 doc's in MSDN (search for
the GetDefaultFolder method).

Willy.

John Smith said:
Guess it's 10.


John Smith said:
The problem with that line by the way is that I'm not passing it the folder
type (in this case contacts...Outlook.OlDefaultFolders.olFolderContacts),
but I don't know what constant I should use for that.



John Smith said:
Thanks Nicholas .

I guess I'm more just looking for examples because the way that I
expect
things to work, currently is not. For instance, the below fails on the
fourth line (while trying to get the default folder) with an
unspecified
exception. I'm sure the mistake is small, but some examples sure would
speed up my debugging:
Type oType = Type.GetTypeFromProgID("Outlook.Application");

Object oApp = Activator.CreateInstance(oType);

Object oNameSpace = oApp.GetType().InvokeMember("GetNamespace",
BindingFlags.GetProperty, null, oApp, new object[1]{"MAPI"});

Object oFolder = oNameSpace.GetType().InvokeMember("GetDefaultFolder",
BindingFlags.GetProperty, null, oNameSpace, null);

Object oAllFolders = oFolder.GetType().InvokeMember("Folders",
BindingFlags.GetProperty, null, oFolder, null);

Object oCurFolder = oAllFolders.GetType().InvokeMember("Add",
BindingFlags.InvokeMethod, null, oAllFolders, new object[1]{"folderName"});



"Nicholas Paldino [.NET/C# MVP]" <[email protected]>
wrote in
message John,

Are you having problems with using reflection, or just the object
model
of outlook? If it is the latter, then check out the article on MSDN
titled
"Automating Outlook from a Visual Basic Applications", located at (watch
for
line wrap):
http://msdn.microsoft.com/library/d...tomatingOutlookFromVisualBasicApplication.asp
It will give you a basic idea of the object model, and should
lead you
to more detailed references.

If you are looking for a reference on reflection, then check out the
section of the .NET Framework developers guide titled "Reflection
Overview",
located at (watch for line wrap):
http://msdn.microsoft.com/library/d...n-us/cpguide/html/cpconReflectionOverview.asp
Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hey,

I'm having a difficult time finding some good examples of late binding
Outlook in C#. Anyone know of any good sites out there? I've googled
and
MSDN'ed, but have come up a bit empty.

IT MUST BE LATE-BINDING THOUGH.

I need to be able to open an existing contact folder or create a
new
contact
folder, and add new contacts to it.

Thanks!
 
The benefits being you can easily support multiple versions of Outlook. If
you know of an easier solution though to handle a company that's Office 97
and up....I'm all ears. I got the late-binding working, but it sure does
stink.
 
Willy Denoyette said:
Contacts default folder = 5, Consult the CDO 1.2.1 doc's in MSDN (search
for the GetDefaultFolder method).

Sorry, was looking at the mapi folder types, the outlook (version 11) folder
types are:

typedef enum {
olFolderDeletedItems = 3,
olFolderOutbox = 4,
olFolderSentMail = 5,
olFolderInbox = 6,
olFolderCalendar = 9,
olFolderContacts = 10,
olFolderJournal = 11,
olFolderNotes = 12,
olFolderTasks = 13,
olFolderDrafts = 16,
olPublicFoldersAllPublicFolders = 18,
olFolderConflicts = 19,
olFolderSyncIssues = 20,
olFolderLocalFailures = 21,
olFolderServerFailures = 22,
olFolderJunk = 23
} OlDefaultFolders;

Use oleview.exe to obtain the enum values for your version of the object
library.

Willy.
 
John Smith said:
The benefits being you can easily support multiple versions of Outlook.
If
you know of an easier solution though to handle a company that's Office 97
and up....I'm all ears. I got the late-binding working, but it sure does
stink.

The OOM was developed to provide an automatision interface to:
- enable Office (VBA) applications to access and extend the Outlook message
store.
- enable some form of management of the outlook (client) environment using
scripting languages in a late-bound fashion.

So what you are doing now is use C# as if it was a scripting language, so
you are loosing strong typing, intelisense support, performance, just to
name a few in favor of a so called "version independency". However, there
are other languages in .NET, like VB.NET and JScript.Net that support
late-binding at the language level, which make them better suited for this
kind of COM interop scenario.
Another remark is that when using late binding you are limiting yourself to
a single version of the object library (f.i. Outlook97), why not create an
interop assembly using the outlook97 olb and early bind against this one,
you will never take advantage of newer versions anyway,

Willy.
 
Back
Top