Outlook programming in VB.Net

  • Thread starter Thread starter rajesh
  • Start date Start date
R

rajesh

Please take a look at the following code snippet.

Dim OutlookApplication As Outlook.Application
Dim OutlookNameSpace As Outlook.NameSpace
Dim outlookAppointmentItem As Outlook.AppointmentItem

OutlookApplication = New Outlook.Application()
OutlookNameSpace = OutlookApplication.GetNamespace("mapi")

outlookAppointmentItem = DirectCast(OutlookApplication.CreateItem
_(Outlook.OlItemType.olAppointmentItem), AppointmentItem)

When I attempt to create an appointment, the system throws an
exception saying 'An unhandled exception of type
'System.Runtime.InteropServices.COMException' occurred'. ' The
information store could not be opened.' However, this code works fine
if my outlook is open on the workstation. but, when outlook is closed
it does not work. Cannot we make this code work while outlook is
closed too? All I need is to create an appointment in outlook even
when outlook is closed.
Please clarify this.
Regards,
Rajesh
 
Rajesh,
However, this code works fine
if my outlook is open on the workstation. but, when outlook is closed
it does not work.
If Outlook is not open, have you considered (attempted) opening Outlook?

Something like:
OutlookApplication = New Outlook.Application()
OutlookNameSpace = OutlookApplication.GetNamespace("mapi") OutlookNameSpace.Logon

outlookAppointmentItem = DirectCast(OutlookApplication.CreateItem
_(Outlook.OlItemType.olAppointmentItem), AppointmentItem)

OutlookNameSpace.Logoff

You may need to supply some parameters to the Logon method.

For a plethora of samples & articles on using Outlook with .NET see:
http://www.microeye.com/resources/res_outlookvsnet.htm

For a plehora of automating Outlook with VBA, VB6, and VBScript see:
http://www.outlookcode.com/

Hope this helps
Jay
 
Jay,
thanks for the response. Yes, I did use this code.
Me.mOutlookNameSpace.Logon("", "", False, True)
It still throws the error. What could be the possible solution?
Apart from this, can I not log on to another user's outlook profile
from my machine if I have the userid and password?
Regards,
Rajesh
 
Rajesh,
Are you logging into your profile (as you statement shows) or someone
else's?

If you are not authorized to login into another person's Mailbox,
NameSpace.Login will not let you and you will get an exception.

I am unable to try, I want to say you are constrained to being logged into a
single profile at a time, so if you are already logged in, you won't be able
to login a second time.

Whether you can login to two profiles or not. I would simple use the
NameSpace.GetSharedDefaultFolder from my first login, assuming the second
mailbox gave you authority to their Mailbox & folders...

Hope this helps
Jay

Jay,
thanks for the response. Yes, I did use this code.
Me.mOutlookNameSpace.Logon("", "", False, True)
It still throws the error. What could be the possible solution?
Apart from this, can I not log on to another user's outlook profile
from my machine if I have the userid and password?
Regards,
Rajesh


If Outlook is not open, have you considered (attempted) opening Outlook?

Something like:

OutlookNameSpace.Logoff

You may need to supply some parameters to the Logon method.

For a plethora of samples & articles on using Outlook with .NET see:
http://www.microeye.com/resources/res_outlookvsnet.htm

For a plehora of automating Outlook with VBA, VB6, and VBScript see:
http://www.outlookcode.com/

Hope this helps
Jay
[/QUOTE]
 
Rajesh,
Me.mOutlookNameSpace.Logon("", "", False, True)

It appears you are attempting to log into your profile, not a second
profile.

Can you be significantly more clear on what exactly you are attempting?

Further info:

The Outlook Object Model (NameSpace.Logon) can only log into a single
profile at one time. You would need to log out of the first profile to log
into the second.

If you use CDO 1.2.1 (not specifically supported on .NET, however its usable
with the VS.NET generated Interop Assembly, samples on the previously listed
website) you can log into multiple profiles. CDO 1.2.1 is an optional
install on Outlook XP & Outlook 2003 from your Outlook/Office Setup CD-ROM.

Are you attempting multiple profiles or multiple Mailboxes? My suggestion of
GetSharedDefaultFOlder will actually be a second mailbox (which is why I
would normally be using a second profile anyway)...

Hope this helps
Jay

Jay,
thanks for the response. Yes, I did use this code.
Me.mOutlookNameSpace.Logon("", "", False, True)
It still throws the error. What could be the possible solution?
Apart from this, can I not log on to another user's outlook profile
from my machine if I have the userid and password?
Regards,
Rajesh


If Outlook is not open, have you considered (attempted) opening Outlook?

Something like:

OutlookNameSpace.Logoff

You may need to supply some parameters to the Logon method.

For a plethora of samples & articles on using Outlook with .NET see:
http://www.microeye.com/resources/res_outlookvsnet.htm

For a plehora of automating Outlook with VBA, VB6, and VBScript see:
http://www.outlookcode.com/

Hope this helps
Jay
[/QUOTE]
 
Back
Top