1

I cannot figure out how to convert the recording time returned as per below to a datetime. My code is:

Shell shell = new Shell();
Folder folder = shell.NameSpace("D:\Recorded Tv");  
string recordingTime = folder.GetDetailsOf(WTVfile, 260);  
string[] formats = { @"dd\/MM\/yyyy", @"d\/MM\/yyyy h:mm tt", @"d\/MM\/yyyy" };
DateTime recordingDateTime = DateTime.Now;

DateTime.TryParseExact(recordingTime, formats, CultureInfo.InvariantCulture, DateTimeStyles.None, out recordingDateTime);

The issue is that the string value in recordingTime for all intensive purposes looks fine to the naked eye, in the above case, "07/03/2014 7:30 PM" but it clearly is not being returned as I'm expecting as after the code above, recordingDateTime is "01/01/1000 12:00:00 AM"

If I copy the value in recordingTime to the clip board and paste it into the code pane and wrap it in rabbit's ears and go to save, it gives me a unicode warning.

My question is how do I parse the recordingTime string to be in the same culture?? as is expected by the TryParseExact method call?

I hope that's clearer :)

thanks

Matt

mattpm
  • 1,310
  • 2
  • 19
  • 26
  • 1
    Your `DateTime.TryParseExact` returns `true`. I don't see anything wrong. What is your actual question exactly? – Soner Gönül May 04 '14 at 13:03
  • Is there a reason you aren't using the FileInfo and/or DirectoryInfo classes instead? – Brian Booth May 04 '14 at 15:59
  • Hi Soner, hopefully my edits will make it clearer. It's the value returned in the variable that is not being parsed correctly perhaps due to character set mismatches?? – mattpm May 04 '14 at 23:31
  • Hi Brian, this is an extended property that I'm trying to obtain - I've hopefully cleared this up. Note, I also tried going via ExtendedProperty but this bizarrely gave a different time value to what was shown in the properties dialog. – mattpm May 04 '14 at 23:32

1 Answers1

1

Stripping non-printable characters via the regex expression proffered here resolved this for me:

val = Regex.Replace(val, @"[^\u0000-\u007F]", string.Empty);
Community
  • 1
  • 1
mattpm
  • 1,310
  • 2
  • 19
  • 26