[UiPath] How to setup config file and read variables

Setting up a config file for your workflows is an efficient way to configure the initial settings of your workflow environment. Variables that refer to path locations, URLs, and other config information that you need to setup when moving your workflow from one environment to another are better placed inside a config file. Think of it as not having to go inside UiPath studio to update your variables every now and then. Instead, you can just create a config file in Ms Excel, and read it in your workflow.

Here's how:

1. Create your config file in the same folder where your workflow is.

In this example, I named the config file as FileConfig.xlsx.
You can place it anywhere actually, but I preferred it to be inside the same folder where the workflow is so that I only to need to refer to its filename, and not its full path, when reading it.



2. Set your variables using two columns



Variable names on Column A, then values on Column B.

3. Read your config file and store it in a DataTable



Use the Read Range (Workbook) activity to read the config file and store it in a DataTable.

4. Access your config variables using the DataTable.Select method



var config_var = DataTable.Select("[Column Name]='variable name'")(0)(1).ToString


Use the select method to return the row that matches the variable name in the Var column of your config file, and (0)(1) index to refer to the second column of the first matched row. 

That's it!

If you need to add more config variables on the excel file, you should likewise add another Assign activity in your workflow to fetch the new variable.

Hope this helps!
Share: