Get latest text file from a folder using uipath-C# code

What is the C# expression to get latest text file from a folder?

@MANISHA_V_ARORA
give a try on:

new DirectoryInfo("C:\\MyDirectory").GetFiles().OrderByDescending(f => f.LastWriteTime).First();

OR

Directory.GetFiles("C:\\MyDirectory","*.txt").OrderByDescending(f => new FileInfo(f).LastWriteTime).First();

error

Thank you peter for a quick help, but i get an error:(

@MANISHA_V_ARORA
some members reported similar issues (a possible relationship to infrastructure and not to code statement) when using c#- Lets take @loginerror into the loop for getting a feedback on this.

@MANISHA_V_ARORA - just checking…is ADSFilepath is a variable ? If yes , that was given inside the quotes …but it should not…please check…

1 Like

Yes it is a variable, I removed the quotes too same error.

Hi @MANISHA_V_ARORA

I’ve seen someone resolve a similar syntax issue by installing .NET Framework 4.8. Could you give it a try?

And also, please check all the other packages required per your Windows version here:

Yay!It worked!
Thank you Maciej,

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