Hello All,
I am looping through the excel files in the folder , but getting the error unable to cast object of type ‘System.Char’ to type ‘System.String’ as shown below,
Inputfilepath and folder paths are string variables.
Can I please know how resolve this error.
Thanks.
Anil_G
(Anil Gorthi)
May 16, 2024, 10:33am
2
@sushmitha.e
May i know why are you looping through a string?
a loop on string will give characters in loop and not string
Remove .ToString from the For each list items
cheers
vrdabberu
(Varunraj Dabberu)
May 16, 2024, 10:33am
3
Hi @sushmitha.e
In For Each pass only Input_file_path
and Argument Type will be System.String. Do not pass .ToString in For Each.
Regards
lrtetala
(Lakshman Reddy)
May 16, 2024, 10:47am
4
Hi @sushmitha.e
No need to use For each loop you are taking one file from folder based on your syntax.You can directly use that variable.
Cheers!!
Yep @lrtetala , if we want to read all the files not only one file ,
Directory.GetFiles(FolderPath,“*.xlsx”).OrderByDescending(Function(d) New FileInfo(d).CreationTime).ToList(0)
In the above path, what should we provide instead of List(0) , to read all the files.
lrtetala
(Lakshman Reddy)
May 16, 2024, 11:10am
6
@sushmitha.e
Directory.GetFiles(FolderPath, "*.xlsx").OrderByDescending(Function(d) New FileInfo(d).CreationTime).ToArray()
Input_file_path variable is of datatype System.String[ ]
Cheers!!
@sushmitha.e ,
First thing, remove the .ToString and second change the Argument type to string array.
Thanks,
Ashok
Yes @ashokkarale , I have changed thanks for replying.
Yes @vrdabberu , I have changed. Thanks for replying.
Yep @Anil_G , removed them. Thanks for replying.
1 Like
vrdabberu
(Varunraj Dabberu)
May 16, 2024, 11:39am
11
Perfect @sushmitha.e the topic can be closed.
Forum FAQ - How to mark a post as a solution
This document is part of our beginners guide .
This article will teach you how to properly mark a post as a solution.
We were closely following our last UiPath Forum feedback round! topic and carefully extracted all the bits of feedback that was provided. As such, we would like to tackle the topic of solutions on our Forum and how to properly use them.
When is the topic resolved?
The topic can be considered resolved when the topic author has fo…
Regards
postwick
(Paul Ostwick)
May 16, 2024, 12:31pm
12
If Input_file_path is string, you don’t need .ToString on the end of it.
You also don’t need to create extra variables (FolderPath, Input_file_path). You also don’t need .ToList on the end of GetFiles, it’s already an array.
Drop in a new For Each and put this directly into “list of items”:
Directory.GetFiles("D:\SUSHMA....","*.xlsx").OrderByDescending(Function (d) New FileInfo(d).CreationTime)