A
anders
I try to make a outlook-addin that integrates with a webservice....
I create one folder with ten subfolders. I add a Listener to each
folder....
When a email is dropped in one of these subfolders, an event is called.
This event calls a Webservice....
After I have dropped ex. 6-7 emailitems in my foldes, my listener
disappers ...
Any ideas ?
My code :
Public Class Connect
Implements Extensibility.IDTExtensibility2
Dim applicationObject as Object
Dim addInInstance As Object
Shared Service As New MyWebservice.outlookService
Shared CookieContainer As New Net.CookieContainer
Dim OutlookApp As Outlook.Application
Dim NewFolder As Outlook.MAPIFolder
Public Sub OnBeginShutdown(ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnBeginShutdown
End Sub
Public Sub OnAddInsUpdate(ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnAddInsUpdate
End Sub
Public Sub OnStartupComplete(ByRef custom As System.Array)
Implements Extensibility.IDTExtensibility2.OnStartupComplete
End Sub
Public Sub OnDisconnection(ByVal RemoveMode As
Extensibility.ext_DisconnectMode, ByRef custom As System.Array)
Implements Extensibility.IDTExtensibility2.OnDisconnection
End Sub
Public Sub OnConnection(ByVal application As Object, ByVal
connectMode As Extensibility.ext_ConnectMode, ByVal addInInst As
Object, ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnConnection
applicationObject = application
addInInstance = addInInst
outlookapp = CType(applicationObject, Outlook.Application)
Dim oNS As Outlook.NameSpace = OutlookApp.GetNamespace("MAPI")
Dim oInbox As Outlook.MAPIFolder =
oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
Dim RootFolder As Outlook.MAPIFolder = CType(oInbox.Parent,
Outlook.MAPIFolder)
Dim Caption As String = "Testmappe"
'If already Exsist, Then remove
Try
Dim i As Integer
Dim CurrentFolder As Outlook.MAPIFolder
If RootFolder.Folders.Count > 0 Then
For i = 1 To RootFolder.Folders.Count
CurrentFolder = RootFolder.Folders.Item(i)
If String.Compare(CurrentFolder.Name, Caption,
False) = 0 Then
RootFolder.Folders.Remove(i)
End If
Next
End If
Catch ex As Exception
Windows.Forms.MessageBox.Show(ex.ToString)
End Try
'Add TestFolder to root
NewFolder = RootFolder.Folders.Add(Caption)
'Add 10 subfolders
For n As Integer = 1 To 10
Dim folder As Outlook.MAPIFolder =
NewFolder.Folders.Add("folder " & n)
'Add Eventlistener
AddHandler folder.Items.itemadd, AddressOf
Me.MyListener.DoEvent
Next
Service.CookieContainer = Me.CookieContainer
End Sub
Dim MyListener As New Listener
Private Class Listener
Public Sub DoEvent(ByVal item As Object)
Windows.Forms.MessageBox.Show("item dropped on folder")
Service.IsLoggedIn()
End Sub
End Class
End Class
I create one folder with ten subfolders. I add a Listener to each
folder....
When a email is dropped in one of these subfolders, an event is called.
This event calls a Webservice....
After I have dropped ex. 6-7 emailitems in my foldes, my listener
disappers ...
Any ideas ?
My code :
Public Class Connect
Implements Extensibility.IDTExtensibility2
Dim applicationObject as Object
Dim addInInstance As Object
Shared Service As New MyWebservice.outlookService
Shared CookieContainer As New Net.CookieContainer
Dim OutlookApp As Outlook.Application
Dim NewFolder As Outlook.MAPIFolder
Public Sub OnBeginShutdown(ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnBeginShutdown
End Sub
Public Sub OnAddInsUpdate(ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnAddInsUpdate
End Sub
Public Sub OnStartupComplete(ByRef custom As System.Array)
Implements Extensibility.IDTExtensibility2.OnStartupComplete
End Sub
Public Sub OnDisconnection(ByVal RemoveMode As
Extensibility.ext_DisconnectMode, ByRef custom As System.Array)
Implements Extensibility.IDTExtensibility2.OnDisconnection
End Sub
Public Sub OnConnection(ByVal application As Object, ByVal
connectMode As Extensibility.ext_ConnectMode, ByVal addInInst As
Object, ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnConnection
applicationObject = application
addInInstance = addInInst
outlookapp = CType(applicationObject, Outlook.Application)
Dim oNS As Outlook.NameSpace = OutlookApp.GetNamespace("MAPI")
Dim oInbox As Outlook.MAPIFolder =
oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
Dim RootFolder As Outlook.MAPIFolder = CType(oInbox.Parent,
Outlook.MAPIFolder)
Dim Caption As String = "Testmappe"
'If already Exsist, Then remove
Try
Dim i As Integer
Dim CurrentFolder As Outlook.MAPIFolder
If RootFolder.Folders.Count > 0 Then
For i = 1 To RootFolder.Folders.Count
CurrentFolder = RootFolder.Folders.Item(i)
If String.Compare(CurrentFolder.Name, Caption,
False) = 0 Then
RootFolder.Folders.Remove(i)
End If
Next
End If
Catch ex As Exception
Windows.Forms.MessageBox.Show(ex.ToString)
End Try
'Add TestFolder to root
NewFolder = RootFolder.Folders.Add(Caption)
'Add 10 subfolders
For n As Integer = 1 To 10
Dim folder As Outlook.MAPIFolder =
NewFolder.Folders.Add("folder " & n)
'Add Eventlistener
AddHandler folder.Items.itemadd, AddressOf
Me.MyListener.DoEvent
Next
Service.CookieContainer = Me.CookieContainer
End Sub
Dim MyListener As New Listener
Private Class Listener
Public Sub DoEvent(ByVal item As Object)
Windows.Forms.MessageBox.Show("item dropped on folder")
Service.IsLoggedIn()
End Sub
End Class
End Class