S
sme
Hi,
I am using Visual Studio .NET 2003 application in order to get access to a
shared folder's contacts. I have "Referenced" the COM library for Outlook
2003.
Below you may find a sample code that loops through a specific user's
contects.
The pronle is that from the 1000 contacts that are stored in the shared
folder I can get only say 200 of them. The remaining 800 failed to be casted
to ContactItem event though the type of these items are ContactItems.
I checked the Outlook version of these contact items but most of them are in
the same version as the other 200 that I can process.
Is it a problem of .NET Interop?
Any help on this would be very important in order to proceed with our project.
Dim oApp As Outlook.Application = CreateObject("Outlook.Application",
"localhost")
' Get NameSpace and Logon.
Dim oNS As Outlook.NameSpace = oApp.GetNamespace("mapi")
oNS.Logon()
Dim outrecp As Outlook.Recipient
outrecp = oNS.CreateRecipient("ikr")
outrecp.Resolve()
' Get the first contact from the Contacts folder.
Dim cContacts As Outlook.MAPIFolder =
oNS.GetSharedDefaultFolder(outrecp, Outlook.OlDefaultFolders.olFolderContacts)
Dim oItems As Outlook.Items = cContacts.Items
Dim oCt As Outlook.ContactItem
Dim ic As Int32 = 0
Try
Dim xx As Object
xx = oItems.GetFirst()
While Not xx Is Nothing
Try
oCt = CType(xx, Outlook.ContactItem)
ic = ic + 1
Catch ex As Exception
' This fails even though the xx is of type ContactItem
Console.WriteLine(TypeName(xx))
oCt = Nothing
End Try
If Not oCt Is Nothing Then
' Display some common properties.
Console.WriteLine(oCt.FullName)
End If
xx = oItems.GetNext
End While
Console.WriteLine(ic)
Finally
oNS.Logoff()
' Clean up.
oApp = Nothing
oNS = Nothing
oItems = Nothing
oCt = Nothing
End Try
I am using Visual Studio .NET 2003 application in order to get access to a
shared folder's contacts. I have "Referenced" the COM library for Outlook
2003.
Below you may find a sample code that loops through a specific user's
contects.
The pronle is that from the 1000 contacts that are stored in the shared
folder I can get only say 200 of them. The remaining 800 failed to be casted
to ContactItem event though the type of these items are ContactItems.
I checked the Outlook version of these contact items but most of them are in
the same version as the other 200 that I can process.
Is it a problem of .NET Interop?
Any help on this would be very important in order to proceed with our project.
Dim oApp As Outlook.Application = CreateObject("Outlook.Application",
"localhost")
' Get NameSpace and Logon.
Dim oNS As Outlook.NameSpace = oApp.GetNamespace("mapi")
oNS.Logon()
Dim outrecp As Outlook.Recipient
outrecp = oNS.CreateRecipient("ikr")
outrecp.Resolve()
' Get the first contact from the Contacts folder.
Dim cContacts As Outlook.MAPIFolder =
oNS.GetSharedDefaultFolder(outrecp, Outlook.OlDefaultFolders.olFolderContacts)
Dim oItems As Outlook.Items = cContacts.Items
Dim oCt As Outlook.ContactItem
Dim ic As Int32 = 0
Try
Dim xx As Object
xx = oItems.GetFirst()
While Not xx Is Nothing
Try
oCt = CType(xx, Outlook.ContactItem)
ic = ic + 1
Catch ex As Exception
' This fails even though the xx is of type ContactItem
Console.WriteLine(TypeName(xx))
oCt = Nothing
End Try
If Not oCt Is Nothing Then
' Display some common properties.
Console.WriteLine(oCt.FullName)
End If
xx = oItems.GetNext
End While
Console.WriteLine(ic)
Finally
oNS.Logoff()
' Clean up.
oApp = Nothing
oNS = Nothing
oItems = Nothing
oCt = Nothing
End Try