Click here to Skip to main content
12,402,889 members (73,393 online)
Rate this:
Please Sign up or sign in to vote.
See more: C#
hi all,

How to write string array into app config(c#) file and how to read those array values into our .cs file.

Thanks in advance...
Posted 19-Mar-12 21:04pm
Dinesh Mani 20-Mar-12 3:30am
Why do you want to write data into your app config???
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

probably the easiest way to do this is to enter the value of the key with a delimeter (eg a comma). Use the string's Split function to split the values and there you have your array. Depending on the type of your needed array, you'll need to convert.

config file
<add key="myarray" value="1,5,6,8,9" />

Code behind
string myarrayvalue = ConfigurationManager.AppSettings["myarray"];
string [] str_array = myarrayvalue.Split(new string[]{","}, StringSplitOptions.RemoveEmptyValues);
//if needed as eg. an integer.
int [] myintarray = new int[str_array.Length];
for(int i = 0; i < str_array.Length; i++){
  int output;
  if(int.TryParse(str_array[i], out output){
    myintarray[i] = output;
    myintarray[i] = -1;

This is a pretty basic question, please start out with a good book.
Oshtri Deka 20-Mar-12 4:02am
Old school ;).
IzetFazlinovic 31-Aug-14 20:37pm
"This is pretty basic question...", but question was "How to write string array into app config(c#) file...". It seems this part of question is not pretty basic for you - no answer...
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

There is an existing class that can do just that: CommaDelimitedStringCollectionConverter Class[^]

There is an example as part of the ConfigurationConverterClass description[^]
Oshtri Deka 20-Mar-12 4:03am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.160721.1 | Last Updated 20 Mar 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100