CSV To Xlsx

I have referred to the above post for fetching latest csv file and converting it into Excel workbook
But i am geting the CSV extension every time which is causing issue for me


Input Argument : String.Join(" ",Directory.GetFiles(Folder_Path,”*.csv”).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Take(1))

Output Argument : String.Join(" ",Directory.GetFiles(Folder_Path,”*.csv”).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Take(1)) + “xlsx”

Please help

You can use Path.GetFileNameWithoutExtension(fileName) to get the filename without the extension.

Path.GetFileNameWithoutExtension(String.Join(" ",Directory.GetFiles(Folder_Path, "*.csv").OrderByDescending(Function(d) New FileInfo(d).CreationTime).Take(1))) + ".xlsx"

Thx @ptrobot
I tried this but the output is saving in different directory, i dont want to move files from one place to other.

Pls help

Sorry, you are correct. It only returns the filename without the path. Path.ChangeExtension() is the function you should be using instead.

Path.ChangeExtension(String.Join(" ",Directory.GetFiles(Folder_Path,”*.csv”).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Take(1)), “.xlsx”)



Thx a lot it worked

1 Like

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