B
Brian P. Hammer
All - I am having an issue when programming a VB.net app and getting data
from the Outlook address book. I have a button on my form that allows a
user to select a contact from the Outlook address book. I have no problem
displaying it and getting values from the address book, but the values are
not what I expect. I get a seesion to Outlook, logon, and then display the
address book with oSession.AddressBook(Title:="Asset Advisory",
RecipLists:=1) The address book displays fine and I can add a name from any
of the address lists.
When I click the "to" the name properly shows up and then clicking OK closes
the form and I set a couple properties for strUser = CStr(orecip(1).Name) &
strEmail = CStr(orecip(1).Address).
orecip.address properly shows the email address but orecip.Name does not.
It always shows the "Display As" for the email address and not the Full Name
or File As for the contact record.
What is the best way to show an address list and then be able to get to the
underlying data such as the name, email address, business address and all
the other stuff?
I have tried this using CDO and Outlook Objecgt Model with no luck.
Thanks,
Brian
Dim om As New Outlook.SecurityManager
Dim oSession As MAPI.Session = Nothing
Dim orecip As Object = Nothing
Dim strProfileInfo As String = appProperties.Properties.ExchangeServer &
vbLf & appProperties.Properties.UserName
Dim blnIsOpen As Boolean
Err.Clear()
om.DisableCDOWarnings = True
oSession = CreateObject("MAPI.Session")
Try
oSession.Logon(ProfileName:=appProperties.Properties.EmailProfileName,
NewSession:=False, ShowDialog:=False)
blnIsOpen = True
Catch
Try
oSession.Logon(ProfileName:=appProperties.Properties.EmailProfileName,
NewSession:=True, NoMail:=True) ', ShowDialog:=False,
ProfileInfo:=strProfileInfo)
Catch ex As Exception
MessageBox.Show("Could not establish a connection to Outlook. Try opening
Outlook and then trying again.", appConstants.Contstants.gstrcAppTitle,
MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Function
End Try
blnIsOpen = False
End Try
Try
orecip = oSession.AddressBook(Title:="Asset Advisory", RecipLists:=1)
strUser = CStr(orecip(1).Name)
strEmail = CStr(orecip(1).Address)
Catch ex As System.Runtime.InteropServices.COMException
strUser = String.Empty
strEmail = String.Empty
Return False
Finally
If Not (oSession Is Nothing) Then
oSession.Logoff()
oSession = Nothing
End If
om.DisableCDOWarnings = False
End Try
from the Outlook address book. I have a button on my form that allows a
user to select a contact from the Outlook address book. I have no problem
displaying it and getting values from the address book, but the values are
not what I expect. I get a seesion to Outlook, logon, and then display the
address book with oSession.AddressBook(Title:="Asset Advisory",
RecipLists:=1) The address book displays fine and I can add a name from any
of the address lists.
When I click the "to" the name properly shows up and then clicking OK closes
the form and I set a couple properties for strUser = CStr(orecip(1).Name) &
strEmail = CStr(orecip(1).Address).
orecip.address properly shows the email address but orecip.Name does not.
It always shows the "Display As" for the email address and not the Full Name
or File As for the contact record.
What is the best way to show an address list and then be able to get to the
underlying data such as the name, email address, business address and all
the other stuff?
I have tried this using CDO and Outlook Objecgt Model with no luck.
Thanks,
Brian
Dim om As New Outlook.SecurityManager
Dim oSession As MAPI.Session = Nothing
Dim orecip As Object = Nothing
Dim strProfileInfo As String = appProperties.Properties.ExchangeServer &
vbLf & appProperties.Properties.UserName
Dim blnIsOpen As Boolean
Err.Clear()
om.DisableCDOWarnings = True
oSession = CreateObject("MAPI.Session")
Try
oSession.Logon(ProfileName:=appProperties.Properties.EmailProfileName,
NewSession:=False, ShowDialog:=False)
blnIsOpen = True
Catch
Try
oSession.Logon(ProfileName:=appProperties.Properties.EmailProfileName,
NewSession:=True, NoMail:=True) ', ShowDialog:=False,
ProfileInfo:=strProfileInfo)
Catch ex As Exception
MessageBox.Show("Could not establish a connection to Outlook. Try opening
Outlook and then trying again.", appConstants.Contstants.gstrcAppTitle,
MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Function
End Try
blnIsOpen = False
End Try
Try
orecip = oSession.AddressBook(Title:="Asset Advisory", RecipLists:=1)
strUser = CStr(orecip(1).Name)
strEmail = CStr(orecip(1).Address)
Catch ex As System.Runtime.InteropServices.COMException
strUser = String.Empty
strEmail = String.Empty
Return False
Finally
If Not (oSession Is Nothing) Then
oSession.Logoff()
oSession = Nothing
End If
om.DisableCDOWarnings = False
End Try