473,466 Members | 1,381 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Release Outlook Application object

Hi.
I'm trying to access the appointments from MS Outlook 2003 using the interop
assembly. Here is the code using .Net Framework 2.0 beta:

Microsoft.Office.Interop.Outlook.Application m_coOutlookApp =
new Microsoft.Office.Interop.Outlook.Application();
NameSpace coNameSpace = m_coOutlookApp.GetNamespace("MAPI");
coNameSpace.Logon("Outlook", null, false, true);
MAPIFolder coCalendarFolder =
coNameSpace.GetDefaultFolder(OlDefaultFolders.olFo lderCalendar);
Items coItems = coCalendarFolder.Items;
foreach (object coObj in coItems)
{
AppointmentItem coAppointment = coObj as AppointmentItem;
if (null == coAppointment)
{
continue; //this isn't an appointment.
}
Console.WriteLine(coAppointment.Subject);
}
coNameSpace.Logoff();
m_coOutlookApp = null;
The code works fine, BUT:
1) I cannot find a way to release the Application object. The "Outlook.exe"
process stays loaded until my application ends (some other work is done after
checking the appointments). I already tried:
a) using "false" as value for the NewSession parameter of the Logon method;
b) calling m_coOutlookApp.Quit();
c) calling 2 times GC.Collect();
GC.WaitForPendingFinalizers();
d) calling Marshal.ReleaseComObject() until the reference count is 0;
e) using the same code without Logon(), Logoff();
So, any ideas ?
2) Sometimes if Outlook is already running when the application starts, it
stoppes responding, and cannot be closed by the user.
Sometimes if my code already run(and the "Outlook.exe" process is yet
loaded), and the user tries to start Outlook, an "Operation failed"
messagebox pops up. The user is then unable to start Outlook until my
application is closed.
How could I handle these situations?

Thanks
Nov 17 '05 #1
1 9353
Try this

http://support.microsoft.com/?kbid=317109
"Francisc Molnar" <Francisc Mo****@discussions.microsoft.com> wrote in
message news:58**********************************@microsof t.com...
Hi.
I'm trying to access the appointments from MS Outlook 2003 using the
interop
assembly. Here is the code using .Net Framework 2.0 beta:

Microsoft.Office.Interop.Outlook.Application m_coOutlookApp =
new Microsoft.Office.Interop.Outlook.Application();
NameSpace coNameSpace = m_coOutlookApp.GetNamespace("MAPI");
coNameSpace.Logon("Outlook", null, false, true);
MAPIFolder coCalendarFolder =
coNameSpace.GetDefaultFolder(OlDefaultFolders.olFo lderCalendar);
Items coItems = coCalendarFolder.Items;
foreach (object coObj in coItems)
{
AppointmentItem coAppointment = coObj as AppointmentItem;
if (null == coAppointment)
{
continue; //this isn't an appointment.
}
Console.WriteLine(coAppointment.Subject);
}
coNameSpace.Logoff();
m_coOutlookApp = null;
The code works fine, BUT:
1) I cannot find a way to release the Application object. The
"Outlook.exe"
process stays loaded until my application ends (some other work is done
after
checking the appointments). I already tried:
a) using "false" as value for the NewSession parameter of the Logon
method;
b) calling m_coOutlookApp.Quit();
c) calling 2 times GC.Collect();
GC.WaitForPendingFinalizers();
d) calling Marshal.ReleaseComObject() until the reference count is 0;
e) using the same code without Logon(), Logoff();
So, any ideas ?
2) Sometimes if Outlook is already running when the application starts, it
stoppes responding, and cannot be closed by the user.
Sometimes if my code already run(and the "Outlook.exe" process is yet
loaded), and the user tries to start Outlook, an "Operation failed"
messagebox pops up. The user is then unable to start Outlook until my
application is closed.
How could I handle these situations?

Thanks

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: HvG | last post by:
I'm sure this is a trivial question, but I cannot create an Outlook Object from a WebForm app, but can from a console app. or a Windows app. My COM knowledge is very poor sorry. ...
1
by: Peter | last post by:
I found this code and it works great. Is there any way to up date the code to export attachments to (c:\Exports)? =================================================== Dim olFolderCalendar As...
6
by: Jonathan Smith | last post by:
I am getting "Type Outlook.Application is not defined" on the line: Dim olApp as New Outlook.Application() I have added a reference to Outlook 11.0 Object Library, but the error is still...
3
by: tony_pez | last post by:
First timer be gentle. I have this code I am trying to put into a vb.net addin for ol2003. I get the error Outlook.Application and Outlook.Selection is not declared. I have installed the PIA's...
1
by: Rico | last post by:
Hello, Hope someone can help here, I'm trying to modify the following code to use an automation object so I don't have deal with CRAPPY REFERENCES! The reason being is that this will be going...
0
by: Roger | last post by:
when I attempt to create the outlook.application object in a windows environment, it works, but when I use the same code in ASP.Net, it throws a "server exception error". Googled the error and...
5
by: Bruno Windels | last post by:
Hi, I am developping an application in C# that creates outlook contacts from a database. For the outlook part of the application, I use the outlook COM object (Version 11 from Office 2003). If a...
7
by: Markus Donath | last post by:
I want to create an Outlook-appointment using .NET VC. My Visual Basic example starts with: Dim oApp As Microsoft.Office.Interop.Outlook.Application = New...
1
by: MyWaterloo | last post by:
Hi, I am currently using this code I found on the internet to send an appointment to Outlook: orm_frmAppointments!ApptDate = ! 'Form_frmAppointments!ApptTime = Me! Form_frmAppointments!Appt =...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.