Error getting latest file downloaded c#

Hi there,

Trying to get the latest file with this function:

System.IO.Directory.GetFiles(path).OrderByDescending(Function(d) New FileInfo(d).CreationTime).First

But it seems function and new are not recognized:

Can anyone give me a hand, pls?
Note: My project is in C#.

Thanks !!!

Hi @javierdavidh Can you try below code once.

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

@javierdavidh for your reference

Folder path (Files path) - String
Latestfile - String

Thanks! I didi it but still getting same error:

It’s like the reserved commands (Function and New) are not recognized…

Hi @javierdavidh can you please try to paste exact code which i have sent to you.

Take assign activity and try the code which i have sent

Remove in the beginning


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

Same error:


@javierdavidh Can i know which activity you are using to execute that code

It’s an assign activity:


C# Syntax:

Directory.GetFiles("path").OrderByDescending(d => new FileInfo(d).CreationTime).First();

add System.IO to the imports

@javierdavidh Check this (131.0 KB)

@javierdavidh If same code is not working in your system means check for missing Namespaces and Packages - update them

Hi @javierdavidh,

What about below


Sequence9.xaml (3.5 KB)

Directory.GetFiles(stPath).OrderByDescending(Function(d) New FileInfo(d).LastModifiedDate).Tolist(0)

Note: Dont use “CreationTime” it will take value base on Time so use “LastModifiedDate”


Thanks !!
It works !!

For your kind information

@Learner007 Thanks for all your help !! It was a syntax issue, cause I am using C#, all your samples were in VB.

Thanks !

@javierdavidh ok cool

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