While Using the Syntax for getting the latest file created in C# Windows Project, I am getting the error, can anyone please provide the solution. Syntax Mentioned below in Screenshot

While Using the Syntax for getting the latest file created in C# Windows Project, I am getting the error, can anyone please provide the solution. Syntax Mentioned in Screenshot.

Hi can you try this

`

String.Join(“”,Directory.GetFiles(FilePath, “*”, SearchOption.AllDirectories).OrderByDescending(Function(d) New FileInfo(d).CreationTime).FirstOrDefault())
`

@Chakravarthi_Koppuravuri

Let me know its working or not

@Chakravarthi_Koppuravuri

Not Working @Praveen_Mudhiraj. Facing the below Error.

Use the same script as u had earlier
Just replace . With , in the place where cursor is there in the image m
Should be like “*”,
Now it’s with dot instead of comma


@Chakravarthi_Koppuravuri

It seems like there is a syntax error in the code. The code you’ve provided is not written correctly. The correct way to use String.Join with a file path is to join a list of file paths into a single string. Here’s the corrected code:

You can use this separately

Directory.GetFiles(directoryPath, “*”, SearchOption.AllDirectories).OrderByDescending(Function(d) New FileInfo(d).CreationTime).FirstOrDefault()

or you can go with this also

Take the assign activity and store the paths
this way
Filepaths = Directory.GetFiles(directoryPath, “*”, SearchOption.AllDirectories).OrderByDescending(Function(d) New FileInfo(d).CreationTime).FirstOrDefault()

strvariable = strvariable +“,”+Filepaths

so it will add the paths based on the " , "

@Chakravarthi_Koppuravuri

@Palaniyappan I have included comma but again getting the same issue. Check the Syntax that was used in the below screenshot.

Shown Syntax is VB.Net Syntax. So what is needed Code in C# or VB.Net?

@ppr Not about the Language I am mentioning. I am mentioning about the Project Type (Windows & Windows-Legacy).

I have used the same syntax in C# Windows-legacy Project for that I haven’t get any error. But while using in C# Windows Project I am facing the issue. Find the Screenshots attached.

Let us, not mixup Project Compatibility like Windows, Leagcy
And Programming Language like VB.Net, C#

From your Screenshot we do see, C# is used


(Blue Box mark)

So a C# Sysntax could look like:

Directory.GetFiles("YourPath", "*", SearchOption.AllDirectories).OrderByDescending(d => new FileInfo(d).CreationTime).FirstOrDefault("");

Kindly note: it is case sensitive e.g. New vs. new

1 Like

It’s working.

Thanks Alot @ppr

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