Well it wasn’t to be all smooth sailing in my XMP adventure. It turns out dates will always be a problem in life. The BitmapMetadata class has a property DateTaken that is a string! When I copied the date from the backup file to the current file it was swapping the days and months around?
Whats wrong with this i thought?
destMetadata.DateTaken = sourceMetadata.DateTaken;
Download trusty Reflector to the travel laptop and voila!
It turns out the property getter uses DateTime.FromFiletime to get the string. It appears this uses the Current Culture to format the date. The setter parses the passed in value using Convert.ToDateTime(value, CultureInfo.InvariantCulture);
I maybe missing something and I am sure it is by design, but surely they could have used a consistent culture to save me from this? Especially on my honeymoon! ![]()
DateTime fromDate = Convert.ToDateTime(sourceMetaData.DateTaken, CultureInfo.CurrentCulture);
destMetadata.DateTaken = fromDate.ToString(CultureInfo.InvariantCulture.DateTimeFormat);
Posted by adammills
Posted by adammills