Uploading CSV - "IF"

Dears,

I have A CSV file the contains a column inside with links to other 5 files. I need to Use “Read CSV” then “IF” in order to to UI path to understand that if it found (Links) in under the column link, It should get this file and upload it to a specific website - that I will choose - Otherwise do nothing.

What workflow and formula should I create??

1 Like

Hi @Mahmoud_Rageh_MiddleEast,

I didn’t understand your process 100%, but you can try this sequence:

  1. Use “Read CSV” activity to read your file and store the output value in a DataTable variable
  2. Use “Output Data Table” activity to write our DataTable to String, and store this value in a String variable.
  3. Use “Matches” activity and configure your regular expression, and store output value to a variable of type System.Collections.Generic.IEnumerable<System.Text.RegularExpressions.Match>
    Tip: You can choose URL and test UiPath default RegEx for URLs
  4. Use “For each” activity using previously variable. Inside your for each, you will set your activities to upload your file (open browser, clicks, type intos, etc.)

This is kind of a draft solution because I didn’t understand you process completely, if you want to share more details about your process… I can improve this solution

Thanks a lot for you your Prompt reply. I think it`s very close to what I need to execute using UI path but I will clarify more to you what I need to accomplish :-

1 - I have a website that I need to upload certain CSV files onto it.
2 - The links for these CSV file will be extracted from “Alteryx” in another CSV files that contains a column called (Links) that will have the link for each file in my Computer.
3- I need UI Path to read these links in side that CSV file and Go to each file and upload it to the website.

Attached the below workflow sequence in which i did the below steps :-
1 - Opened the website.
2- Added some “Click” activities in order to reach to the “Upload files”.
3 - After that, I added another (Sequence) in order to read (CSV)
4 - and there, I need UI Path to read the column (Links) inside that CSV in step 3 and then go to each link file - Also know that these links represents other CSV files on my computer - and upload them onto the website.

I have attached the workflow and a screenshots of the workflow.

Appreciate your kind support.

image Workflow - Upload file  - Sequence Screenshots

Group Project Connect.xaml (15.3 KB)

1 Like

@Mahmoud_Rageh_MiddleEast

You have to use ForEach Activity instead of ForEach Row activity for looping through the Directory

Follow Link

Hope this helps you

Thanks

1 Like

Hey @Mahmoud_Rageh_MiddleEast,

Just adding some points…

  • "For Each Row"activity is only used when you are working with DataTable
  • When you use “For Each” activity, you also need to set “TypeArgument” field. In this case set to String, because Directory.GetFiles method returns Array of String.

I would suggest doing Read CSV first, so you can check that their are links in the file before trying to upload them.

Then, you don’t actually need to use a GetFile() if you have the links to the files already in the CSV, assuming those links contain the full filepath to the files.

Next thing I would check is if you can select multiple files in the Upload file dialogue box. If that’s the case, you don’t actually need to use a For Each at all.

For a multi-select Upload dialogue box, it would be like:

Read CSV to dtSample
IF dtSample.Rows.Count > 0 AndAlso dtSample.Select.Where(Function(r) Not File.Exists(r("Links").ToString.Trim) ).Count = 0
   Else Throw BusinessRuleException that a file does not exist

IF dtSample.Rows.Count > 0

  Open Browser
  Navigate to Upload
  Type Into: """"+String.Join(""",""",dtSample.Select.Select(Function(r) r("Links").ToString.Trim).ToArray)+""""

Note that the IFs can be adjusted as you want, but I just put in a way to see if any of the files don’t exist. You may choose to instead upload the ones that exist still, which then you can use the .Where() to filter out the ones that exist and the ones that don’t exist.

Using the String.Join(), I show how you can input all the filepaths into the upload dialogue box for a multi-select dialogue.

For the single-select dialogue, it would be like this with a For Each:

Read CSV to dtSample
IF dtSample.Rows.Count > 0 AndAlso dtSample.Select.Where(Function(r) Not File.Exists(r("Links").ToString.Trim) ).Count = 0
   Else Throw BusinessRuleException that a file does not exist

IF dtSample.Rows.Count > 0

  Open Browser
  Navigate to Upload
  For Each link In dtSample.Select.Select(Function(r) r("Links").ToString.Trim).ToArray
    Click Upload button
    Type Into: link
    Click button to add

Hopefully my insights add some extra ideas.

Regards.