Outlook add-in and Extended Properties in Exchange
-
Monday, March 15, 2010 1:36 AMHello,
I'm writing a project where I want to associate a project (retrieved from list of active projects from company's DB) to an Outlook item (mailitem, or task, or contact) and save this selection to Exchange (probably using extended properties). The associacion would be done in a custom form region add-in, that would display the available regions in a combo box. A user would open an item, and associate it to an appropriate project shown on the region. Another module (a separate project running on a server) would then read all items stored in Exchange, and examine their extended properties to produce "items by project" reports". How can write an extended property to exchange from the form region? I'm developing my form region using VB in VS2008 with use of VSOT, and my server-side project is using Exchange WebServices managed API 1.0 I know I can refer to the selected item using Me.OutlookItem, but where do I go from there? I'm kinda new to Exchange and Office development so please, be as verbose as you can.
All Replies
-
Friday, March 19, 2010 2:32 PM
I finally found the answer myself. Turns out the Extended Properties at the OOB layer are the UserProperties. So to set an extended property in an Outlook Addon to an Outlook item, I do this:
Dim usrProp As Microsoft.Office.Interop.Outlook.UserProperty
If TypeOf (Me.OutlookItem) Is Outlook.MailItem Then
If Me.OutlookFormRegion.FormRegionMode = _
Outlook.OlFormRegionMode.olFormRegionRead Then
usrProp = CType(Me.OutlookItem, Outlook.MailItem).UserProperties. _
Add("Projet", Outlook.OlUserPropertyType.olText, True)
usrProp.Value = cboProjets.SelectedValue 'cboProjects contains the project selected to be assigned to this e-mail
CType(Me.OutlookItem, Outlook.MailItem).Save()
End If
End IfThen to retrieve all items that users marked as being associated to a specific projects, I can do this in an app using EWS managed API:
Private exPropDef as ExtendedPropertyDefinition
Private Sub Initialize()
exPropDef = New ExtendedPropertyDefinition( _
DefaultExtendedPropertySet.PublicStrings, "Projet", MapiPropertyType.String)
service = New ExchangeService(ExchangeVersion.Exchange2010)
service.UseDefaultCredentials = True
' Hook up the cert callback.
System.Net.ServicePointManager.ServerCertificateValidationCallback = Function( _
obj As Object, _
certificate As X509Certificate, _
chain As X509Chain, _
errors As SslPolicyErrors) True 'temporary ;)
' Validate the certificate and return true or false as appropriate.
' Note that it not a good practice to always return true because not
' all certificates should be trusted.
service.Credentials = New WebCredentials("user", "password", "domain")
service.AutodiscoverUrl("user@domain.com")
End SubPublic Function ReadMessagesbyProject(Optional ByVal iProject_Id As Short = -1) As CLMailMessages
Dim mi As New CLMailMessages() 'a custom collection object
Dim view As ItemView = New ItemView(10)
view.OrderBy.Add(ItemSchema.DateTimeReceived, SortDirection.Ascending)
view.PropertySet = New PropertySet( _
BasePropertySet.IdOnly, _
ItemSchema.DisplayTo, _
ItemSchema.Subject, _
ItemSchema.DateTimeReceived, _
exPropDef)
Dim findResults As FindItemsResults(Of Item) = service.FindItems( _
WellKnownFolderName.Inbox, _
New SearchFilter.SearchFilterCollection( _
LogicalOperator.Or, _
New SearchFilter.Exists(exPropDef)), _
view)
For Each Item In findResults
If Item.GetType Is GetType(EmailMessage) Then
If Item.ExtendedProperties.Count > 0 Then
For Each ep As ExtendedProperty In Item.ExtendedProperties
If ep.PropertyDefinition = exPropDef AndAlso ep.Value = iProject_id Then
mi.Add(New CLMailMessage(Item.DisplayTo, Item.Subject, ep.Value, Item.DateTimeReceived))
End If
Next
End If
End If
Next Item
Return mi
End FunctionHope it helps all those who read it.
- Marked As Answer by mr1uk45z Friday, March 19, 2010 2:32 PM

