Hello,
I am working on an application in Visual Studio 2010 VB.Net, going against
Exchange Server 2007 SP1. I have a shared mailbox from which I need to
obtain mail items and set Extended (custom) properties, and then be able to
retrieve the values of the properties using EmailMessage.TryGetProperty.
I have no problem defining extended properties and setting the values, and
I can see them with Outlook Spy and EWSEditor, and can even see them when I
loop through the item's extended properties after having loaded the extended
property definitions into a property set as in the code below.
However, when I try to use the message's TryGetProperty method, it returns false.
I have searched exhaustively on TryGetProperty, and found some indications that
the code has to be very specific with regard to the returned property value TYPE,
so the code below lists the different calls I have tried using return variables
of different types in an attempt to get the method to work. The method returns
false for all tries, and for the return type of string (strPropValue) and object
(objPropValue), the variables are returned uninitialized (Nothing).
Interestingly, any of the calls made with mapi type return variables return the
value: ApplicationTime {0}, which is of course, the first enumeration in the
mapitype enum.
Can someone please show me the error of my ways?
Thanks in advance,
Jeff
Private Function PreserveItemIDs(ByRef objMsg As EmailMessage) As Boolean
Dim blnFunctionReturn As Boolean = False
Dim objPropSetID As New Guid("{00020329-0000-0000-C000-000000000046}")
'^ GUID for DefaultExtendedPropertySet.PublicStrings
Dim objExtendedPropertyDefintion0 As New ExtendedPropertyDefinition( _
objPropSetID, "My OriginalItemID", MapiPropertyType.String)
Dim objExtendedPropertyDefintion1 As New ExtendedPropertyDefinition( _
objPropSetID, "My ItemIDHistory", MapiPropertyType.String)
Dim mapiTypeAppTime As New MapiPropertyType
Dim mapiTypeString As New MapiPropertyType
Dim mapiTypeObject As New MapiPropertyType
Dim strPropValue As String = String.Empty
Dim objPropValue As Object = Nothing
Dim objPS As New PropertySet(BasePropertySet.FirstClassProperties)
Try
mapiTypeAppTime = MapiPropertyType.ApplicationTime
mapiTypeString = MapiPropertyType.String
mapiTypeObject = MapiPropertyType.Object
objPS.Add(objExtendedPropertyDefintion0)
objPS.Add(objExtendedPropertyDefintion1)
objMsg.Load(objPS)
For Each objExProperty In objMsg.ExtendedProperties
If objExProperty.PropertyDefinition.Name = "My OriginalItemID" Then
Debug.Print(objExProperty.PropertyDefinition.Name)
End If
Next
If objMsg.TryGetProperty(objExtendedPropertyDefintion0, strPropValue) Then
End If
If objMsg.TryGetProperty(objExtendedPropertyDefintion1, strPropValue) Then
End If
If objMsg.TryGetProperty(objExtendedPropertyDefintion0, objPropValue) Then
End If
If objMsg.TryGetProperty(objExtendedPropertyDefintion1, objPropValue) Then
End If
If objMsg.TryGetProperty(objExtendedPropertyDefintion0, mapiTypeString) Then
End If
If objMsg.TryGetProperty(objExtendedPropertyDefintion1, mapiTypeString) Then
End If
If objMsg.TryGetProperty(objExtendedPropertyDefintion0, mapiTypeObject) Then
End If
If objMsg.TryGetProperty(objExtendedPropertyDefintion1, mapiTypeObject) Then
End If
If objMsg.TryGetProperty(objExtendedPropertyDefintion0, mapiTypeAppTime) Then
End If
If objMsg.TryGetProperty(objExtendedPropertyDefintion1, mapiTypeAppTime) Then
End If
blnFunctionReturn = True
Catch ex As Exception
Throw
Finally
objPropSetID = Nothing
objExtendedPropertyDefintion = Nothing
End Try
End Function