Saturday, 15 February 2014

c# - Open file by part of his name -



c# - Open file by part of his name -

i need open file folder part of name. have files in 1 folder illustration files in c:\temp\ names of files in format id_yyyymmdd.pdf, id number, id of file , , id unique, yyyymmdd date in format year,month,day. in programme id , need find file id, check date when file created , , if there new version of file(blob in database) need write new file disk , open it, if lastly version of file need open.(i have pdfs blob, , need check on hard disk lastly version file.) know how write pdf blob file cannot find way open(or find) file part of name , , thaen sec part(date) compare it.

any suggestions?

sample: on hard disk have files:

c:\temp\12345_20140508.pdf c:\temp\12346_20140508.pdf

in database table have

id(12345) date(08-may-2014) , pdf1 file blob. id(12346) date(10-may-2014) , pdf2 file blob.

now in programme select id "12345" because dates same need open file 12345_20140508.pdf when select id 12346 need first file file database because date in database newer date on hard disk, remove file 12346_20140508.pdf , save new file 12346_20140510.pdf , open.

if need can alter format of name.

i supposed main problem met "how find newest file id". may can seek code. can find lastly created file start id. 1 time file, thought other things won't problem you.

var directoryinfo = new directoryinfo(@"c:\temp"); var latestfile = directoryinfo.getfiles() .where(f => f.name.startswith("12345_")) .orderbydescending(f => f.creationtime) .firstordefault();

c# date timestamp

No comments:

Post a Comment