C
Chris Thunell
I'm trying to loop through an exchange public folder contact list, get some
information out of each item, and then put it into a vb.net datatable. I
run though the code and all works fine until i get to item 250 i get a
"system.invalid cast exception" and "specified cast is not valid". Once i
get this error and try to go to the next record.. every record after gets
the same error... It's like the com connection to outlook has been lost.
(as a side note, the first time i ran this... it worked all the way
through... i'm not sure what i've done to break it, or if this is an
intermittent problem). You can see by my sample below that i've rem'ed out
different things i've tried.
Any thoughts?
Chris Thunell
(e-mail address removed)
'outlook connection settings
'Dim oApp As outlook.Application = New outlook.Application
Dim oApp As Object = New outlook.Application
'Dim oNS As outlook.NameSpace = oApp.GetNamespace("MAPI")
Dim oNS As Object = oApp.GetNamespace("MAPI")
Dim cContacts As outlook.MAPIFolder = oApp.ActiveExplorer.CurrentFolder
'Dim oItems As outlook.Items = cContacts.Items
Dim oItems As Object = cContacts.Items
' Dim oCT As outlook.ContactItem
Dim oCT As Object
Dim iCount As Int16
Dim X As Int32
Dim NewRow As DataRow
Dim myRow As DataRow
'check to see if the right public folder has been selected
'let's loop through the outlook contacts
'set the counters
X = 1
iCount = 0
iCount = oItems.Count
DoEvents()
oCT = oItems.GetFirst()
For X = X To iCount 'Each oCT In oItems
StatusBar1.Text = "Looking at Outlook Record " & X & " of " & iCount & "."
'find the record in tblCompany
'***** i'm currently getting the error on the following line:
'*****oct.entryID does not give me anything ... it's like it forgot what
"entryID" is.
myRow = Me.DataSet11.tblCompany.FindByOutlookEntryID(oCT.EntryID)
'do some more stuff and then loop to the next outlook contact record
oCT = oItems.GetNext
Next
oApp = Nothing
oItems = Nothing
oCT = Nothing
information out of each item, and then put it into a vb.net datatable. I
run though the code and all works fine until i get to item 250 i get a
"system.invalid cast exception" and "specified cast is not valid". Once i
get this error and try to go to the next record.. every record after gets
the same error... It's like the com connection to outlook has been lost.
(as a side note, the first time i ran this... it worked all the way
through... i'm not sure what i've done to break it, or if this is an
intermittent problem). You can see by my sample below that i've rem'ed out
different things i've tried.
Any thoughts?
Chris Thunell
(e-mail address removed)
'outlook connection settings
'Dim oApp As outlook.Application = New outlook.Application
Dim oApp As Object = New outlook.Application
'Dim oNS As outlook.NameSpace = oApp.GetNamespace("MAPI")
Dim oNS As Object = oApp.GetNamespace("MAPI")
Dim cContacts As outlook.MAPIFolder = oApp.ActiveExplorer.CurrentFolder
'Dim oItems As outlook.Items = cContacts.Items
Dim oItems As Object = cContacts.Items
' Dim oCT As outlook.ContactItem
Dim oCT As Object
Dim iCount As Int16
Dim X As Int32
Dim NewRow As DataRow
Dim myRow As DataRow
'check to see if the right public folder has been selected
'let's loop through the outlook contacts
'set the counters
X = 1
iCount = 0
iCount = oItems.Count
DoEvents()
oCT = oItems.GetFirst()
For X = X To iCount 'Each oCT In oItems
StatusBar1.Text = "Looking at Outlook Record " & X & " of " & iCount & "."
'find the record in tblCompany
'***** i'm currently getting the error on the following line:
'*****oct.entryID does not give me anything ... it's like it forgot what
"entryID" is.
myRow = Me.DataSet11.tblCompany.FindByOutlookEntryID(oCT.EntryID)
'do some more stuff and then loop to the next outlook contact record
oCT = oItems.GetNext
Next
oApp = Nothing
oItems = Nothing
oCT = Nothing