c# - Is there a way to try to guess the date from a filename and, if unable, to gracefully fail? -


i want try (programmatically) guess date file created. it named blabla.2012-06-04.xlw, can guess created june 4th, 2012.

however, if file named else, sitona.potatopanotis.pal, want able give (without attempted conversion datetime causing exception) , present user datetimepicker.

doable?

i've got code:

string substr = selectedfilename.substring(date_begin_pos, date_length); return datetime.parse(substr); 

i'm thinking make sense:

try  {     string substr = selectedfilename.substring(date_begin_pos, date_length);     return datetime.parse(substr); } catch (conversionexception ce)  {     //show form datetimepicker } 

update

it seems should work:

datetime dt; if (!(datetime.tryparse(substr, out dt))) {    . . . 

either can ask directly creation time using file.getcreationtime or if trying guess via file name can use tryparse date , if doesn't work (method return false) show dialog.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -