Click here to Skip to main content
16,021,169 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a list of excel file and i want to select latest excel file on the basis of date.can anyone tell me the code for this.i want to achieve in c#.net.
My format of excel file is:--Weekly_Monthly_Hours_Reference_Sheet_03-28-11.xls
Posted
Comments
Sergey Alexandrovich Kryukov 3-Nov-11 0:07am    
What does it mean: "select Excel file"? Where?
--SA

1 solution

0) Get a date variable for latest date, and string variable for file.
1) Loop through the excel files.
1.1) Get the last 8 characters of name of the file. Ref: GetFileNameWithoutExtension[^], SubString[^]
1.2) Convert them to date. Ref: Convert.ToDateTime[^]
1.3) If it is newer then latest date or latest date is null then store date in latest date, and file name in file variable.
2) When you are out of loop, you'll have the latest file in the file variable.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900