Illegal characters in path when using Directory.GetFiles on WebDav

Hello UiPath-Forum Colleagues,
i want to get the files from a subfolder on webdav.
To do that i am using the command Directory.GetFiles(subfolder).
The target folder is stored in the variable subfolder as string.


UiPath throws an error message: Illegal characters in path.
image
When executing the command on the immediate command line it works, when i use the content of the variable in the Directory.GetFiles command.
image
Note, the folder is on a webdav server, which is mounted as drive Y.
Does anybody have an idea why the Directory.GetFiles command does not work?
Best regards,
Jo

Hi,

Remove Extra Spaces: subfolder.Trim()
Check for Special characters: Webdev not except some special characters
subfolder = subfolder.Trim().Replace(β€œ<”, β€œβ€).Replace(β€œ>”, β€œβ€).Replace(β€œ:”, β€œβ€).Replace(β€œ*”, β€œβ€).Replace(β€œ?”, β€œβ€).Replace(β€œ|”, β€œβ€).Replace(β€œβ€β€œβ€, β€œβ€).Replace(β€œ/”, β€œβ€)
subfolder = Uri.EscapeUriString(subfolder)
FilesArray = Directory.GetFiles(subfolder)

I hope it helps you

Hi,

Is there possibility to contains something wrong character in the path? Can you share the xaml file? It’s no problem if just the activity exists.

Regards,

Hi Rigandu,
i tried the uri.escapeUriString function, but it does not work either


Why does the function find the folder with β€œY:\data\out\VomMandanten\DCB\KSI-Export\20230508_093628_463886”, but not if i use the variable with the string as content?
Best regards, Jo

Hi,

It seems your path string ends with 0x00 (special character). So can you try to remove it OR use Trim(chr(0)) as the following?

"your path string".Trim(chr(0))

image

Regards,

2 Likes

Hello Yoichi,
thank you for the idea. Unfortunately removing the %00 does not work either.


Best regards,
Jo

HI,

Can you share your xaml file? It’s no problem even if unnecessary activities are removed.

Regards,

Hello Yoichi,
this is the xaml file.

The thing is, the directory.getfiles function works when i geht files from windoes directories.
But i am working on webdav. maybe webdav requires another function.
What i do not understand is, that if i use the String itself it works, but when i use the variable that holds the string, it does not work.
Best regards,
Jo

HI,

To isolate cause, can you insert the following expression in Writeline activity then share the content when error occurs?

String.Join(",",tempSubfolder.Select(Function(c) AscW(c).ToString))

Regards,

Hello Yoichi,
your hint with the last character %00 is worthwile looking at.

If i remove the last character, it seems to work. Still got to put it into the Robots workflow and see if it works.

Best regards, Jo

Got it, thank you very much!

1 Like

I removed the workflow file, just as information.

trim(chr(0)) does not work though, i check if subfolder.EndsWith(Nothing) and then remove it with Directory.GetFiles(Left(subfolder, Len(subfolder) - 1))

1 Like

Great to hear the problem is solved.

FYI, as the following expression shows what character exists then we can know which character should be removed.

String.Join(",",tempSubfolder.Select(Function(c) AscW(c).ToString))

Regards,

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