Making use of the PidTagStartDateEtc to calculate the age of an object for Achive and Retention policies
When your dealing with Archive and Retention policies in Exchange 2010 one of the important questions to ask is what property is used to calculate the age of an Item. While it might be tempting to use some of the easy to get to datetime properties the important property to use in relation to Archive and Retention policies is the PidTagStartDateEtc property which is documented in http://msdn.microsoft.com/en-us/library/ee179537%28v=exchg.80%29.aspx.
So as stated this is a composite property with the first 4 bytes belonging to the default retention period if it has been applied then the final 8 bytes gives the UTC Datetime from which the Message object's age is calculated. The following is a quick sample of how to extract this datetime from that property using the EWS Managed API.
ExtendedPropertyDefinition PidTagStartDateEtc = new ExtendedPropertyDefinition(12315, MapiPropertyType.Binary);
Object StartDate = null;
itItem.TryGetProperty(PidTagStartDateEtc, out StartDate);
long fileTime = BitConverter.ToInt64((Byte[])StartDate, 4);
DateTime ItemAge = DateTime.FromFileTime(fileTime);
So as stated this is a composite property with the first 4 bytes belonging to the default retention period if it has been applied then the final 8 bytes gives the UTC Datetime from which the Message object's age is calculated. The following is a quick sample of how to extract this datetime from that property using the EWS Managed API.
ExtendedPropertyDefinition PidTagStartDateEtc = new ExtendedPropertyDefinition(12315, MapiPropertyType.Binary);
Object StartDate = null;
itItem.TryGetProperty(PidTagStartDateEtc, out StartDate);
long fileTime = BitConverter.ToInt64((Byte[])StartDate, 4);
DateTime ItemAge = DateTime.FromFileTime(fileTime);