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:
image

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 system.io in the beginning

Hi,

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

Same error:

Tks!

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

It’s an assign activity:

image

C# Syntax:

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

add System.IO to the imports

@javierdavidh Check this

Latest_File.zip (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

Workflow

Xaml
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,
Rajkumar

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.