0

In window, i can get the date created of the video from properties(right click).
I have a few idea on this but i dont know how to do it.
1. Get the video information directly from video(like in windows),
2. By extracting the video name to get the date created(The video's name is in date format, which is the time it created).
And i also using taglib-sharp to get the video duration and resolution, but i cant find any sample code on how to get the video creation date.

Note: video name in date format - example, 20121119_125550.avi

Edit
Found this code and so far its working

string fileName = Server.MapPath("//video//20121119_125550.avi");
FileInfo fileInfo = new FileInfo(fileName);
DateTime creationTime = fileInfo.CreationTime;

Output: 2012/11/19 12:55:50

For the file's name, i will add another string in name. For example User1-20121119_125550.avi.avi, so it will get complicated after that.

Lynx
  • 259
  • 1
  • 9
  • 26

1 Answers1

1

If you can safely trust your filenames, you may be content with the following:

string file_name = "20121119_125550.avi";
string raw_date = file_name.Split('.')[0];
CultureInfo provider = CultureInfo.InvariantCulture;


string format = "yyyyMMdd_hhmmss";
DateTime result = DateTime.ParseExact(raw_date, format, provider);

Note: You'll likely need to add using System.Globalization; to any file you wish to use this in.

If you just want the date the file was created (What you see in Windows Explorer) you can just use:

string file_path = @"C:\20121119_125550.avi"; //Add the correct path
DateTime result = File.GetCreationTime(file_path);
JoshVarty
  • 9,066
  • 4
  • 52
  • 80
  • Don't use just the first index. Example: `one.two.avi` would just be `one` – Cole Tobin Nov 26 '12 at 04:46
  • I'm assuming that the sample date he provided is representative of the set of all his dates. If they're in varying formats with multiple periods, then he'll have to accommodate for that himself. I can't provide a generic solution if I don't know the formats he's dealing with. – JoshVarty Nov 26 '12 at 04:48
  • Makes sense. I'm just pointing out that a help vampire like him will want that kind of solution. – Cole Tobin Nov 26 '12 at 15:26