Order by Descending

Hello.
I am trying to send the latest file in folder as attachment, but its not working.

Directory.GetFiles(FolderPath,”*”).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Take(1))

thanks

Hi,

Do you need the latest filename as string? if so, the following will work.

Directory.GetFiles(FolderPath,"*").OrderByDescending(Function(d) New FileInfo(d).CreationTime).FirstOrDefault

Regards,

HI @khaled_emad

How about this expression?

Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)+"\Downloads").[Select](Function(x) New FileInfo(x)).Where(Function(f) f.Extension.Equals(".xls")).OrderByDescending(Function(x) x.LastWriteTime).Take(1).ToArray()(0).ToString

Regards
Gokul

@khaled_emad

Please check this

Directory.GetFiles(FolderPath).OrderByDescending(Function(d) New FileInfo(d).CreationTime)(0)

Cheers

Its saying

overload resolution failed because of no accessible ‘orderbydescending’ accepts this number of arguments

I am just trying to get the latest excel workbook created in folder to send it as an attachment in an email

Hi,

Can you share screenshot of your activity with error message?

Regards,

same as this

Hi @khaled_emad

Before the directory.getfiles…please add system.io.directory.getfiles

Cheers

Yeah using that but same probem
I believe its in orderbydescending

Hi,

To isolate cause, can you try the following xaml file?

Sequence1.xaml (5.1 KB)

If it works, can you check if there is difference b/w this and yours?
If they are same, it might be something wrong with your xaml file.

Regards,

thank you.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.