By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,018 Members | 1,163 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,018 IT Pros & Developers. It's quick & easy.

Late Binding Outlook

P: n/a
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!
Nov 16 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
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/de...pplication.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/de...onOverview.asp

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"John Smith" <js@no.com> wrote in message
news:O1****************@TK2MSFTNGP15.phx.gbl...
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!

Nov 16 '05 #2

P: n/a
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("GetDefaultFolde r",
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]" <mv*@spam.guard.caspershouse.com> wrote in
message news:#G**************@tk2msftngp13.phx.gbl...
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/de...pplication.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/de...onOverview.asp
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"John Smith" <js@no.com> wrote in message
news:O1****************@TK2MSFTNGP15.phx.gbl...
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!


Nov 16 '05 #3

P: n/a
The problem with that line by the way is that I'm not passing it the folder
type (in this case contacts...Outlook.OlDefaultFolders.olFolderContac ts),
but I don't know what constant I should use for that.

"John Smith" <js@no.com> wrote in message
news:#B**************@TK2MSFTNGP09.phx.gbl...
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("GetDefaultFolde r",
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]" <mv*@spam.guard.caspershouse.com> wrote in message news:#G**************@tk2msftngp13.phx.gbl...
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/de...pplication.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/de...onOverview.asp

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"John Smith" <js@no.com> wrote in message
news:O1****************@TK2MSFTNGP15.phx.gbl...
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!



Nov 16 '05 #4

P: n/a
Guess it's 10.
"John Smith" <js@no.com> wrote in message
news:#e**************@TK2MSFTNGP15.phx.gbl...
The problem with that line by the way is that I'm not passing it the folder type (in this case contacts...Outlook.OlDefaultFolders.olFolderContac ts),
but I don't know what constant I should use for that.

"John Smith" <js@no.com> wrote in message
news:#B**************@TK2MSFTNGP09.phx.gbl...
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("GetDefaultFolde r",
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]" <mv*@spam.guard.caspershouse.com> wrote

in
message news:#G**************@tk2msftngp13.phx.gbl...
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/de...pplication.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/de...onOverview.asp

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"John Smith" <js@no.com> wrote in message
news:O1****************@TK2MSFTNGP15.phx.gbl...
> 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!
>
>



Nov 16 '05 #5

P: n/a

"John Smith" <js@no.com> wrote in message
news:O1****************@TK2MSFTNGP15.phx.gbl...
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.
Nov 16 '05 #6

P: n/a
Contacts default folder = 5, Consult the CDO 1.2.1 doc's in MSDN (search for
the GetDefaultFolder method).

Willy.

"John Smith" <js@no.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Guess it's 10.
"John Smith" <js@no.com> wrote in message
news:#e**************@TK2MSFTNGP15.phx.gbl...
The problem with that line by the way is that I'm not passing it the

folder
type (in this case contacts...Outlook.OlDefaultFolders.olFolderContac ts),
but I don't know what constant I should use for that.

"John Smith" <js@no.com> wrote in message
news:#B**************@TK2MSFTNGP09.phx.gbl...
> 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("GetDefaultFolde r",
> 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]" <mv*@spam.guard.caspershouse.com>
> wrote

in
> message news:#G**************@tk2msftngp13.phx.gbl...
> > 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/de...pplication.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/de...onOverview.asp
> >
> > Hope this helps.
> >
> >
> > --
> > - Nicholas Paldino [.NET/C# MVP]
> > - mv*@spam.guard.caspershouse.com
> >
> > "John Smith" <js@no.com> wrote in message
> > news:O1****************@TK2MSFTNGP15.phx.gbl...
> > > 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!
> > >
> > >
> >
> >
>
>



Nov 16 '05 #7

P: n/a
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 [MVP]" <wi*************@pandora.be> wrote in message
news:ut**************@tk2msftngp13.phx.gbl...

"John Smith" <js@no.com> wrote in message
news:O1****************@TK2MSFTNGP15.phx.gbl...
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.

Nov 16 '05 #8

P: n/a


"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:uj****************@tk2msftngp13.phx.gbl...
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.
Nov 16 '05 #9

P: n/a


"John Smith" <js@no.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
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.
Nov 16 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.