I
ilan
Hi,
I'm catching the event of opening a task.
in the event handler I'm accessing a config file (I
created Outlook.exe.config in the C:\Program
Files\Microsoft Office\OFFICE11 folder and added "MyVal"
value to it)
I'm getting the correct value from my config file but
it only happens once. The NewInspector event won't fire
again.
Ommiting the line that access the config file results with
this event fires normally.
Any suggestions?
I'm using Outlook 2003 win 2003.
This is the code I use:
namespace MyFirstOutlookAddin
{
using System;
using Microsoft.Office.Core;
using System.Windows.Forms;
using System.Reflection;
using Extensibility;
using System.Runtime.InteropServices;
using System.Configuration;
using System.IO;
[GuidAttribute("EADFD989-C91D-4E2C-9D76-
5DA414736ECD"), ProgId("MyFirstOutlookAddin.Connect")]
public class Connect : Object,
Extensibility.IDTExtensibility2
{
public Outlook.TaskItemClass
outlookItems ;
private Outlook.Application
applicationObject;
private object addInInstance;
public Connect()
{
}
public void OnConnection(object
application, Extensibility.ext_ConnectMode connectMode,
object addInInst, ref System.Array custom)
{
applicationObject =
(Outlook.Application)application;
addInInstance = addInInst;
if (connectMode !=
Extensibility.ext_ConnectMode.ext_cm_Startup)
{
OnStartupComplete(ref
custom);
}
MessageBox.Show("Connected1");
register();
}
public void register()
{
Outlook.NameSpace ns =
applicationObject.GetNamespace("MAPI");
Outlook.MAPIFolder TaskFolder =
ns.GetDefaultFolder
(Outlook.OlDefaultFolders.olFolderTasks);
TaskFolder.Items.ItemChange +=new
Outlook.ItemsEvents_ItemChangeEventHandler
(Items_ItemChange);
applicationObject.Inspectors.NewInspector +=new
Outlook.InspectorsEvents_NewInspectorEventHandler
(Inspectors_NewInspector);
}
private void Connect_Open(ref bool Cancel)
{
MessageBox.Show("Connect_Open");
}
public void OnDisconnection
(Extensibility.ext_DisconnectMode disconnectMode, ref
System.Array custom)
{
MessageBox.Show("Disconnected");
if(disconnectMode !=
Extensibility.ext_DisconnectMode.ext_dm_HostShutdown)
{
OnBeginShutdown(ref
custom);
}
applicationObject = null;
}
public void OnAddInsUpdate(ref
System.Array custom)
{
}
public void OnStartupComplete(ref
System.Array custom)
{
}
public void OnBeginShutdown(ref
System.Array custom)
{
}
private void Connect_FolderSwitch()
{
}
private void Items_ItemChange(object Item)
{
MessageBox.Show("Change");
}
private void Connect_ItemEvents_Event_Open
(ref bool Cancel)
{
MessageBox.Show
("Connect_ItemEvents_Event_Open");
try
{
string val=
ConfigurationSettings.AppSettings["myVal"];
}
catch(Exception ex)
{
throw ex;
}
Cancel = true;
}
private void Inspectors_NewInspector
(Outlook.Inspector Inspector)
{
outlookItems =
(Outlook.TaskItemClass)(Inspector.CurrentItem);
if (Inspector.CurrentItem is
Outlook.TaskItemClass)
{
((Outlook.TaskItemClass)
(Inspector.CurrentItem)).ItemEvents_Event_Open +=new
Outlook.ItemEvents_OpenEventHandler
(Connect_ItemEvents_Event_Open);
((Outlook.TaskItemClass)
(Inspector.CurrentItem)).Open+=new
Outlook.ItemEvents_10_OpenEventHandler(Connect_Open);
}
}
}
}
I'm catching the event of opening a task.
in the event handler I'm accessing a config file (I
created Outlook.exe.config in the C:\Program
Files\Microsoft Office\OFFICE11 folder and added "MyVal"
value to it)
I'm getting the correct value from my config file but
it only happens once. The NewInspector event won't fire
again.
Ommiting the line that access the config file results with
this event fires normally.
Any suggestions?
I'm using Outlook 2003 win 2003.
This is the code I use:
namespace MyFirstOutlookAddin
{
using System;
using Microsoft.Office.Core;
using System.Windows.Forms;
using System.Reflection;
using Extensibility;
using System.Runtime.InteropServices;
using System.Configuration;
using System.IO;
[GuidAttribute("EADFD989-C91D-4E2C-9D76-
5DA414736ECD"), ProgId("MyFirstOutlookAddin.Connect")]
public class Connect : Object,
Extensibility.IDTExtensibility2
{
public Outlook.TaskItemClass
outlookItems ;
private Outlook.Application
applicationObject;
private object addInInstance;
public Connect()
{
}
public void OnConnection(object
application, Extensibility.ext_ConnectMode connectMode,
object addInInst, ref System.Array custom)
{
applicationObject =
(Outlook.Application)application;
addInInstance = addInInst;
if (connectMode !=
Extensibility.ext_ConnectMode.ext_cm_Startup)
{
OnStartupComplete(ref
custom);
}
MessageBox.Show("Connected1");
register();
}
public void register()
{
Outlook.NameSpace ns =
applicationObject.GetNamespace("MAPI");
Outlook.MAPIFolder TaskFolder =
ns.GetDefaultFolder
(Outlook.OlDefaultFolders.olFolderTasks);
TaskFolder.Items.ItemChange +=new
Outlook.ItemsEvents_ItemChangeEventHandler
(Items_ItemChange);
applicationObject.Inspectors.NewInspector +=new
Outlook.InspectorsEvents_NewInspectorEventHandler
(Inspectors_NewInspector);
}
private void Connect_Open(ref bool Cancel)
{
MessageBox.Show("Connect_Open");
}
public void OnDisconnection
(Extensibility.ext_DisconnectMode disconnectMode, ref
System.Array custom)
{
MessageBox.Show("Disconnected");
if(disconnectMode !=
Extensibility.ext_DisconnectMode.ext_dm_HostShutdown)
{
OnBeginShutdown(ref
custom);
}
applicationObject = null;
}
public void OnAddInsUpdate(ref
System.Array custom)
{
}
public void OnStartupComplete(ref
System.Array custom)
{
}
public void OnBeginShutdown(ref
System.Array custom)
{
}
private void Connect_FolderSwitch()
{
}
private void Items_ItemChange(object Item)
{
MessageBox.Show("Change");
}
private void Connect_ItemEvents_Event_Open
(ref bool Cancel)
{
MessageBox.Show
("Connect_ItemEvents_Event_Open");
try
{
string val=
ConfigurationSettings.AppSettings["myVal"];
}
catch(Exception ex)
{
throw ex;
}
Cancel = true;
}
private void Inspectors_NewInspector
(Outlook.Inspector Inspector)
{
outlookItems =
(Outlook.TaskItemClass)(Inspector.CurrentItem);
if (Inspector.CurrentItem is
Outlook.TaskItemClass)
{
((Outlook.TaskItemClass)
(Inspector.CurrentItem)).ItemEvents_Event_Open +=new
Outlook.ItemEvents_OpenEventHandler
(Connect_ItemEvents_Event_Open);
((Outlook.TaskItemClass)
(Inspector.CurrentItem)).Open+=new
Outlook.ItemEvents_10_OpenEventHandler(Connect_Open);
}
}
}
}