Accessing contact folder Problem

  • Thread starter Thread starter Alex
  • Start date Start date
A

Alex

In my add-In when i try to find a contact e-mail, with the function
below:

Private Function getMailByName(ByVal Name As String) As String
Dim outlookObject As Outlook._Application = New
Outlook.Application
Dim folder As Outlook.MAPIFolder =
outlookObject.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)
Dim mailAddress As String = String.Empty

Try
For Each contact As Outlook.ContactItem In folder.Items
If contact.FileAs.Contains(Name) Then
mailAddress = contact.Email1Address
Exit For
End If
Next
Catch ex As Exception
Debug.WriteLine(ex.Message)
Finally
If outlookObject IsNot Nothing Then outlookObject = Nothing
If folder IsNot Nothing Then folder = Nothing
End Try

Return mailAddress
End Function

I get this alert message:

"A program is trying to access e-mail address information stored in
outlook. If this is unexpected ... "

There is any way to programmatically allow the access to contact
folder.
 
Use the trusted Application passed to you in OnConnection, never use a new
Application object, that isn't trusted.
 
Use the trusted Application passed to you in OnConnection, never use a new
Application object, that isn't trusted.














- Show quoted text -

First of all sorry my bad english ...

let me explain my Environment and my Application more accurately:

My dev environment:
Window Vista, Outlook 2007, VSTO SE, VSTOR, VS2005.

The step i've made to build the Add-In Architecture:

Run VS2005 As Administrator, File->New Peoject-> in My Template
section click on the "Office Outlook 2007 Visual Basic Add-In" button

The Following file compose the Defoult solution:
addin_register.reg, AssemblyInfo.vb, Connect.vb, OutlookExplorer.vb,
OutlookInspector.vb, OutlookItem.vb.

I had added to this solution a xml file:

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"
onLoad="Ribbon_OnLoad">
<ribbon>
<tabs>
<tab idMso="TabReadMessage">
<group id="joshProtocol"
getLabel="WidgetsGroup_GetLabel"
visible="1">
<toggleButton id="toggleTaskPane"
size="large"
label="Enable Task Pane"
screentip="Enable Task Pane"
onAction="OnToggleTaskPane"
getImage ="GetImage"
visible="1"
getPressed="GetPressedState"
/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>

I had made some change to the file Connector.VB:

Implements Office.IRibbonExtensibility
Implements Extensibility.IDTExtensibility2

Public Function GetCustomUI(ByVal ......

End Function

Public Sub OnConnection(ByVal application As Object, ...

End Sub

Aplication specific is:
Whea a mail message are open (Inspector class, Events
Outlook.MailItem.open), the RibbonX is shown and The CustomTaskPane is
instanced (As New(ByVal Contact.Email1 String))

the TaskPane constructor accept as parameter a String that is the
return value of the function "getMailByName(ByVal Name As String) As
String"

All of the step explained below are defined in the class Inspector.vb

Trusted application Is defined in Connector.vb class,

Question:

Can i refer to Trusted Aplication in the inspector code?
 
OK, so your having VSTO is irrelevant in this case, what you have is a
shared addin. You can refer to the Application object in a number of ways
from other classes. Either declare an application object as Public in the
Connect class or create a public class for your globals and set that in
OnConnection:

Public app As Outlook.Application

' OnConnection
app = CType(application, Outlook.Application)

Then from other code you can use Connect.app.



<snip>
First of all sorry my bad english ...

let me explain my Environment and my Application more accurately:

My dev environment:
Window Vista, Outlook 2007, VSTO SE, VSTOR, VS2005.

The step i've made to build the Add-In Architecture:

Run VS2005 As Administrator, File->New Peoject-> in My Template
section click on the "Office Outlook 2007 Visual Basic Add-In" button

The Following file compose the Defoult solution:
addin_register.reg, AssemblyInfo.vb, Connect.vb, OutlookExplorer.vb,
OutlookInspector.vb, OutlookItem.vb.

I had added to this solution a xml file:

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"
onLoad="Ribbon_OnLoad">
<ribbon>
<tabs>
<tab idMso="TabReadMessage">
<group id="joshProtocol"
getLabel="WidgetsGroup_GetLabel"
visible="1">
<toggleButton id="toggleTaskPane"
size="large"
label="Enable Task Pane"
screentip="Enable Task Pane"
onAction="OnToggleTaskPane"
getImage ="GetImage"
visible="1"
getPressed="GetPressedState"
/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>

I had made some change to the file Connector.VB:

Implements Office.IRibbonExtensibility
Implements Extensibility.IDTExtensibility2

Public Function GetCustomUI(ByVal ......

End Function

Public Sub OnConnection(ByVal application As Object, ...

End Sub

Aplication specific is:
Whea a mail message are open (Inspector class, Events
Outlook.MailItem.open), the RibbonX is shown and The CustomTaskPane is
instanced (As New(ByVal Contact.Email1 String))

the TaskPane constructor accept as parameter a String that is the
return value of the function "getMailByName(ByVal Name As String) As
String"

All of the step explained below are defined in the class Inspector.vb

Trusted application Is defined in Connector.vb class,

Question:

Can i refer to Trusted Aplication in the inspector code?
 
OK, so your having VSTO is irrelevant in this case, what you have is a
shared addin. You can refer to the Application object in a number of ways
from other classes. Either declare an application object as Public in the
Connect class or create a public class for your globals and set that in
OnConnection:

Public app As Outlook.Application

' OnConnection
app = CType(application, Outlook.Application)

Then from other code you can use Connect.app.



<snip>
First of all sorry my bad english ...

let me explain my Environment and my Application more accurately:

My dev environment:
Window Vista, Outlook 2007, VSTO SE, VSTOR, VS2005.

The step i've made to build the Add-In Architecture:

Run VS2005 As Administrator, File->New Peoject-> in My Template
section click on the "Office Outlook 2007 Visual Basic Add-In" button

The Following file compose the Defoult solution:
addin_register.reg, AssemblyInfo.vb, Connect.vb, OutlookExplorer.vb,
OutlookInspector.vb, OutlookItem.vb.

I had added to this solution a xml file:

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"
onLoad="Ribbon_OnLoad">
<ribbon>
<tabs>
<tab idMso="TabReadMessage">
<group id="joshProtocol"
getLabel="WidgetsGroup_GetLabel"
visible="1">
<toggleButton id="toggleTaskPane"
size="large"
label="Enable Task Pane"
screentip="Enable Task Pane"
onAction="OnToggleTaskPane"
getImage ="GetImage"
visible="1"
getPressed="GetPressedState"
/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>

I had made some change to the file Connector.VB:

Implements Office.IRibbonExtensibility
Implements Extensibility.IDTExtensibility2

Public Function GetCustomUI(ByVal ......

End Function

Public Sub OnConnection(ByVal application As Object, ...

End Sub

Aplication specific is:
Whea a mail message are open (Inspector class, Events
Outlook.MailItem.open), the RibbonX is shown and The CustomTaskPane is
instanced (As New(ByVal Contact.Email1 String))

the TaskPane constructor accept as parameter a String that is the
return value of the function "getMailByName(ByVal Name As String) As
String"

All of the step explained below are defined in the class Inspector.vb

Trusted application Is defined in Connector.vb class,

Question:

Can i refer to Trusted Aplication in the inspector code?

Yes Yes Yes, it work so fine,

thanks a lot Mr Ken Slovak

--Alessio
 
Back
Top