Custom Properties in Outlook

Hello, I am trying to write custom properties to an .msg file using Aspose.Network that I could read from within an Outlook add-in using the Outlook object model. My code is based on this post http://www.aspose.com/community/forums/2/275051/custom-properties-in-an-outlook-form/showthread.aspx.

Using this code I get an error trying to open the message from Outlook, a dialog window opens that says 'Cannot read the item.' This error happens on machines that do not have our Outlook add-in installed, and if I remove the code for adding custom properties the msg file opens correctly, so I think the problem is in that code.

Here is the code I am using to write a custom property -

                        MapiPropertyCollection namedProperties = message.NamedProperties;
                        MapiNamedPropertyMappingStorage mappingStorage = message.NamedPropertyMapping;
                    <SPAN style="COLOR: #2b91af">Guid</SPAN> PS_MAPI = <SPAN style="COLOR: #2b91af">Guid</SPAN>.NewGuid();
                    <SPAN style="COLOR: #2b91af">Guid</SPAN> PS_PUBLIC_STRINGS = <SPAN style="COLOR: #2b91af">Guid</SPAN>.NewGuid();

                    <SPAN style="COLOR: #2b91af">MapiProperty</SPAN> stringProperty = <SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: #2b91af">MapiProperty</SPAN>(mappingStorage.GetNextAvailablePropertyId(<SPAN style="COLOR: #2b91af">MapiPropertyType</SPAN>.PT_LONG), <SPAN style="COLOR: #2b91af">Encoding</SPAN>.Unicode.GetBytes(fileInfo.FileId.ToString()));
                    message.SetProperty(stringProperty);

                    <SPAN style="COLOR: blue">string</SPAN> stringNameId = <SPAN style="COLOR: #a31515">"fileInfo"</SPAN>;
                    mappingStorage.AddNamedPropertyMapping(stringProperty, stringNameId, PS_PUBLIC_STRINGS);</PRE>

Is there another way that I should be doing this? I am using Aspose.Network version 6.7.

Thanks,

Aaron

Hi Aaron,

Thank you for inquiry.

Please use “MapiPropertyType.PT_STRING8” in the below line:

MapiProperty stringProperty = new MapiProperty(mappingStorage.GetNextAvailablePropertyId(MapiPropertyType.PT_LONG), Encoding.Unicode.GetBytes(fileInfo.FileId.ToString()));

This will fix your issue.