Getting a numeric MapiNamedProperty Value

Hi all,
I am using the Aspose.Email.Outlook library with VB.NET and am trying to retrieve the custom property values from a .msg file

I can do this using the code below, however, I can only do this when I have set the column type as Text in Outlook but when I am trying to get the value of a custom property which I have set as Number type I do not get the correct value.

For the message C:/Test.msg I set the value for the TestNum property as 123, but the code below prints out 0000000000C05E40.

How do I change the code below so it prints 123?

I have attached a screenshot to show how I have set up the property in Outlook

Thanks

----------------------------------------------------------------------------------
Dim Msg As MapiMessage = MapiMessage.FromFile(C:/Test.msg)

For Each p As MapiNamedProperty In Msg.NamedProperties.Values

If p.NameId = “TestNum” Then

'this only works if the format is text
'how to get a numeric value
Dim s As String = p.ToString()
Msgbox(s)

End If

Next

Hi Steve,


Thank you for writing to Aspose Support team.

The MapiNamedProperty has different methods such as GetDouble, GetLong, GetInt32 that you can use based on the type of the property added. In your case, you can try the GetLong or GetInt32 to match your needs. Please let us know if we could be of any further help to you in this regard.

Hi,
I have amended the code slightly as below and I am still not getting the correct value. I have commented the code to show what I am getting (I should be getting 123).

If I set the property as an integer property in outlook rather than number, I can get the value 123.

If it helps, I have also used the datatype property which outputs 5 if the field is a “number” field and 3 if it is an “integer” field

----------------------------------------------------------------------------------
Dim Msg As MapiMessage = MapiMessage.FromFile(C:/Test.msg)

For Each p As MapiNamedProperty In Msg.NamedProperties.Values

If p.NameId = “TestNum” Then

Dim l As Long = p.GetLong
MsgBox(l)
'prints 4679262415387361280

Dim i As Integer = p.GetInt32
MsgBox(i)
'prints 0

Dim i1 As Int32 = p.GetInt32
MsgBox(i1)
'prints 0

Dim s As Short = p.GetShort
MsgBox(s)
'prints 0

Dim t As Integer = p.DataType
MsgBox(t)
'prints 5 for number
'prints 3 for integer

End If

Next

Hi Steve,

Following sample code adds such property in a message and then reads it properly. Please give it a try and share the feedback.

Dim message2 As New MapiMessage()
Dim mapiPropertyTag2 As Long = message2.NamedPropertyMapping.GetNextAvailablePropertyId(MapiPropertyType.PT_LONG)
Dim mapiPropertyGuid2 As New Guid("6ed8da90-450b-101b-98da-00aa003f1305")

'Any random Guid
Dim mapiProperty2 As New MapiProperty(mapiPropertyTag2, BitConverter.GetBytes(CLng(123)))
message2.NamedPropertyMapping.AddNamedPropertyMapping(mapiProperty2, "TestNum", mapiPropertyGuid2)
message2.SetProperty(mapiProperty2)
message2.Save("Test.msg")
Dim message1 As MapiMessage = MapiMessage.FromFile("Test.msg")
For Each prop As MapiNamedProperty In message1.NamedProperties.Values
    If prop.NameId = "TestNum" Then
        Dim val As Long = prop.GetLong()
        Console.WriteLine(val)
    End If
Next