You need to use capital MM
to represent Month
instead of small mm
from your sample Date string 07312011
it looks like
first two digits - 07
=> Month
next two digits - 31
=> Date
next four digits - 2011
=> Year
hence your format should be MMddyyyy
EDIT: you need to add 1 after closing the LastIndexOf()
function
Try This:
Paycheck p = new Paycheck(DateTime.ParseExact(file.Substring(
file.LastIndexOf("_") + 1, 6), "MMddyyyy", null), file);