Creating a dictionary from a config file

Hi,

I’m using C# and am trying to learn how to create a dictionary using a config file, but I’ve reached a point where I’m stuck and really need some help! :slightly_smiling_face:

I’ve created a very basic test config file using a spreadsheet ‘config.xlsx’:

image

I’ve initialised a dictionary ‘Out_Config’, assigned a string variable for the config file path and another string variable for the sheet name within the config file. I’ve used a Read Range Workbook activity to create datatable dtConfigTable.

I’m then using a ‘For Each Row in Data Table’ activity:

image

I’m then using a message box, thinking it will display the value:

image

When I run it, I get this error:

image

I know I’m missing a step somewhere, more than likely somewhere in the ‘For Each Row’ activity, but I don’t know where I’ve gone wrong. Please help, I’m SO confused! Here are the variables I’m using:

Thank you for any help! :slightly_smiling_face:

Hi,
Try to use Out_Config(“Name”) = CurrentRow(“Value”)

@paulparkes

You need to use out_Config[currentRow["Name"].ToString] in the assign on left side

As per current design in config variable key is set as Name and not the variable_name

By using currentRow["Name"].ToString you are making the key as variable_name

Cheers

This would be the way :+1:. Just as a minor addition, we need to remember to use trailing parentheses in C# projects in method calls without parameters, so it needs to be x.ToString().

Thank you so much for your help! I changed the assign on the left (in the 'For Each Row in Data Table activity) to: Out_Config[CurrentRow[“Name”].ToString()] and it worked perfectly! Thank you! :slightly_smiling_face:

1 Like

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