I'm having a bit of trouble with a program that I'm writing. The program checks the date created of a file on a remote ftp site, then if it matched today's date it will download the file the upload it to another ftp site. I get the following error when I run the program:
unhandled exception system.formatexception string was not recognized as a valid datetime
Here is the code I'm using to convert the ftp file created date to a datetime
/* Get the Date/Time a File was Created */
string fileDateTime = DownloadftpClient.getFileCreatedDateTime("test.txt");
Console.WriteLine(fileDateTime);
DateTime dateFromString = DateTime.Parse(fileDateTime, System.Globalization.CultureInfo.InvariantCulture.DateTimeFormat);
Console.WriteLine(dateFromString);
Any ideas on what I'm doing wrong here?
If the string returned from the sever is
20121128194042
, then your code needs to be:EDIT
The correct code for the
getFileCreatedDateTime
method should be:(With help from this answer.)
The calling code then becomes: