Assign error?

I use assign activity for get latest file excel as below.

Variable File as string = Directory.GetFiles(“C:\Users\Tiff\Downloads”,"*.csv”,SearchOption.AllDirectories).OrderByDescending(Function(d) New FileInfo(d).CreationTime)(0)

But show error.

File .xaml = Reconcile.xaml (5.4 KB)

Please guide me about it.

Hi @Maria99

Could you delete and try rewrite the code again (think compliler problem).

seems same work for me

Directory.GetFiles(“C:\Userts\Tiff”,"*.csv",SearchOption.AllDirectories).OrderByDescending(function(d) new FileInfo(d).CreationTime)(0)

just put a slash at the end of the folder path

thanks

c:\Users\Tiff\Downloads\ *.csv

Regards,
NaNi

@Maria99
You can achieve the same by following statement

strLastFileFullPath =
new DirectoryInfo("C:\Users\Tiff\Downloads").GetFiles("*.csv", SearchOption.AllDirectories).OrderBy(Function (f) f.CreationTime).Last().FullName

@ppr I use follow you suggest.

But show error as below.

@prasath_S @THIRU_NANI Error same as below.

Directory.GetFiles(“C:\Users\Tiff\Downloads\ *.csv”,SearchOption.AllDirectories).OrderByDescending(Function(d) New FileInfo(d).CreationTime)(0)

Hi @Maria99,

Firstly, may we ask about your project`s expression Language? I think your code and the suggested fixes are using VB syntax, but will not work in C#. You can check that info in your project.json.

“expressionLanguage”: “CSharp”,

Hai Maria99
Check out this it will be work

String.Join(“parameter”,Directory.GetFiles(FolderPath,”*”).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Take(n))

Here:
Take(n): defines how many file paths you require i.e., n=1 or 2 or 3, and goes on.

It will sort the latest file based on creation time from all files.

parameter- It will separate the file paths with this parameter.

If you enter ‘,’ there then the output will be like this filepath1, filepath2.

It will be like this we are combining all the file paths.

If you want only one latest file from a folder then follow as shown below:
String.Join(“ ”,Directory.GetFiles(FolderPath,”*”).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Take(1))

it is validating:
grafik

ensure System.IO is added to the imports:
grafik

@ppr Yes , I have

image

@marci080 File Desktop I use C#.
But normally I use VB.

How to change C# to VB?
I have file .xaml only not have file .json

image

@Maria99
ok this explains the validation issue. @marci080 was refering to the project.json file from your UiPath project. Just close uipath, navigate to Uipath project. locate the project.json file. Edit it in an editor and change the programming languague to VB

@ppr How to change C# to VB?
I have file .xaml only not have file .json

please refer to the post above. it is listing the steps
project.json:
grafik

@ppr You mean edit expression Language in .json right ?

But I have file .xaml only not have file json.

So I don’t know how to edit expression Language.

You have created an UiPath Project, right?
then you wull also have the corresponding project.json.

Please check it on filesystem. Otherwise let us know on detail on how you prepared ypur development environment / UiPath Studio for this XAML. Thanks

Hi @Maria99

When you newly create or open an xaml in UiPath Studio, there are some folders and files generated automatically. Amongst them is the project json file.
(Just like what happened when I opened your Reconcile.xaml file in my Downloads folder.) :sweat_smile:
image

You may learn more about it here

Though I personally do not recommend manually editing the json file because some activities may not work/appear properly and will make debugging more complicated.

Anyways, to address your original issue, maybe you can create a blank project (in VB) and just test first the suggested fix to check if the error no longer appear. Then start from there ~ :sun_with_face:

2 Likes

To me it looks more like a generic syntax error.
The code highlighting suggests that the last part of your expression is interpreted as an unfinished string, purely goin on the syntax highlighting.

If I look closely at the screenshot it looks as if different types of double quotes are used, which might cause the syntax error. Did you by any chance copy paste the ‘c:\users…’ part from a word document?

Your expression looks fine in syntax. Try typing it in manually fully once, and see if that makes the difference…

Yes, I agree @Jeroen_van_Loon ! My original answer was about syntax error including the misused quotation marks since C# is somehow “strict”
Though I found out that if in VB, @Maria99 `s original code will amazingly work even without changing the mismatched quotations! :smiley:

VB
Directory.GetFiles(“C:\Users\Tiff\Downloads”,"*.csv”,SearchOption.AllDirectories).OrderByDescending(Function(d) New FileInfo(d).CreationTime)(0)
or
Directory.GetFiles("C:\Users\Tiff\Downloads","*.csv",SearchOption.AllDirectories).OrderByDescending(Function(d) New FileInfo(d).CreationTime)(0)


C# 
Directory.GetFiles("C:\\Users\\Tiff\\Downloads","*.csv",SearchOption.AllDirectories).OrderByDescending(d => new FileInfo(d).CreationTime).ElementAt(0)

Though this ticket isresolved, I just want to add this detail for future reference.

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