none
Trying to use EmailMessage.TryGetProperty | Exchange 2007 RRS feed

  • Question

  • 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

    Tuesday, October 2, 2012 9:49 PM

Answers

  • Rather then defining the GUID for the PublicString property set (which you dont need to do)

            Dim objPropSetID As New Guid("{00020329-0000-0000-C000-000000000046}")
                '^ GUID for DefaultExtendedPropertySet.PublicStrings

    You should use the enumeration the reason for doing this is that the server will resolve it to the DistinguishedPropertySetId and your TryGet will always fail because its looking for the GUID rather then the DistinguishedPropertySetId. If you set tracing on your request you'll see what I mean eg you see this go out

              <t:AdditionalProperties>
                <t:ExtendedFieldURI PropertySetId="00020329-0000-0000-c000-000000000
    046" PropertyName="blah balh" PropertyType="String" />
              </t:AdditionalProperties>

    and this come back

                    <t:ExtendedProperty>
                      <t:ExtendedFieldURI DistinguishedPropertySetId="PublicStrings"
     PropertyName="blah balh" PropertyType="String" />
                      <t:Value>test</t:Value>
                    </t:ExtendedProperty>
    Cheers
    Glen
    • Marked as answer by JToddLed Wednesday, October 3, 2012 11:04 PM
    Wednesday, October 3, 2012 7:02 AM

All replies

  • Rather then defining the GUID for the PublicString property set (which you dont need to do)

            Dim objPropSetID As New Guid("{00020329-0000-0000-C000-000000000046}")
                '^ GUID for DefaultExtendedPropertySet.PublicStrings

    You should use the enumeration the reason for doing this is that the server will resolve it to the DistinguishedPropertySetId and your TryGet will always fail because its looking for the GUID rather then the DistinguishedPropertySetId. If you set tracing on your request you'll see what I mean eg you see this go out

              <t:AdditionalProperties>
                <t:ExtendedFieldURI PropertySetId="00020329-0000-0000-c000-000000000
    046" PropertyName="blah balh" PropertyType="String" />
              </t:AdditionalProperties>

    and this come back

                    <t:ExtendedProperty>
                      <t:ExtendedFieldURI DistinguishedPropertySetId="PublicStrings"
     PropertyName="blah balh" PropertyType="String" />
                      <t:Value>test</t:Value>
                    </t:ExtendedProperty>
    Cheers
    Glen
    • Marked as answer by JToddLed Wednesday, October 3, 2012 11:04 PM
    Wednesday, October 3, 2012 7:02 AM
  • Great!

    That indeed solved my problem.  Thanks!

    However, I will add the following for those like me who need everthing spelled out:

    Instead of these declarations...
            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)

    These are the correct declarations...
            Dim objExtendedPropertyDefintion0 As New ExtendedPropertyDefinition( _
                DefaultExtendedPropertySet.PublicStrings, "My OriginalItemID", MapiPropertyType.String)
            Dim objExtendedPropertyDefintion1 As New ExtendedPropertyDefinition( _
                DefaultExtendedPropertySet.PublicStrings, "My ItemIDHistory", MapiPropertyType.String)

    Best Regards,

    Jeff


    Jeff Ledbetter

    Wednesday, October 3, 2012 11:07 PM