473,785 Members | 2,449 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

app.config problem in reading multiple values per key, very stuck no idea

hello, i have a app.config file like so
<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>
<appSettings>
<add key="rdbUser1Cp u1" value="Cpu1,tes t"/>
</appSettings>
</configuration>

I understand it is possible to have mutliple values per key that when
you use getvalues is suppoded to return a String[] but it dont seem to
work

Eg

String[] temp;

temp = ConfigurationMa nager.AppSettin gs.GetValues("r dbUser1Cpu1");

this compiles and runs fine with no errors except

it does not return a string array with 2 elements houseing each
seperate value

(What i expected was temp[0] =" Cpu1" and temp[1] = "test" )

instead it returns a single element array of "Cpu1,test1 " in the first
index.

temp[0] = "Cpu1,test"
temp[1] = out of bounds index

Am i misunderstandin g how it should work, or am i doing this wrong.

thanks for any help

Peted
Aug 27 '07 #1
4 17741
Peted wrote:
hello, i have a app.config file like so
<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>
<appSettings>
<add key="rdbUser1Cp u1" value="Cpu1,tes t"/>
</appSettings>
</configuration>

I understand it is possible to have mutliple values per key that when
you use getvalues is suppoded to return a String[] but it dont seem to
work
Well, I think it's obvious that there's no reason to expect the comma
character to be somehow understood as a delimiter for a string array.

As far as the specific question goes, IMHO a better approach to dealing
with this sort of issue would be to go the other way, by calling
NameValueCollec tion.Add() with each element in a string array and then
looking at what the resulting XML looks like.

Now, that said, while I haven't done much myself with this area of the
API, I will bet you anything that if you simply include multiple "add"
records for a given key, that would do exactly what you want. For example:

<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>
<appSettings>
<add key="rdbUser1Cp u1" value="Cpu1"/>
<add key="rdbUser1Cp u1" value="test"/>
</appSettings>
</configuration>

Pete
Aug 27 '07 #2
>
>Now, that said, while I haven't done much myself with this area of the
API, I will bet you anything that if you simply include multiple "add"
records for a given key, that would do exactly what you want. For example:

<?xml version="1.0" encoding="utf-8" ?>
<configuration >
<appSettings>
<add key="rdbUser1Cp u1" value="Cpu1"/>
<add key="rdbUser1Cp u1" value="test"/>
</appSettings>
</configuration>

Pete

No that dont work
Ive already tried this, if you multiple add statements withe the same
key name you get this below as ive shown it
<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>
<appSettings>
<add key="rdbUser1Cp u1" value="Cpu1,tes t"/>
</appSettings>
</configuration>

multiple add statements result in comma delimited string as in my
example

this is why i do expect the comma to be the delimter for the returned
string array. From everything ive read on the net it should work the
way im expecting it to work but it does not.

Other people on the net have asked exactly the same question but i
cannot find a single instance of any explanation or an example of why
it does not work or how it can be made to work.
any advice appreciated

thanks

Peted
Aug 27 '07 #3
Hi,

If the comma should be a delimiter, isn't it just possible to split the
string:

String[] temp =
ConfigurationMa nager.AppSettin gs.GetValues("r dbUser1Cpu1").T oString().Split (',');

- Alexander
"Peted" wrote in message news:jr******** *************** *********@4ax.c om...
hello, i have a app.config file like so
<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>
<appSettings>
<add key="rdbUser1Cp u1" value="Cpu1,tes t"/>
</appSettings>
</configuration>

I understand it is possible to have mutliple values per key that when
you use getvalues is suppoded to return a String[] but it dont seem to
work

Eg

String[] temp;

temp = ConfigurationMa nager.AppSettin gs.GetValues("r dbUser1Cpu1");

this compiles and runs fine with no errors except

it does not return a string array with 2 elements houseing each
seperate value

(What i expected was temp[0] =" Cpu1" and temp[1] = "test" )

instead it returns a single element array of "Cpu1,test1 " in the first
index.

temp[0] = "Cpu1,test"
temp[1] = out of bounds index

Am i misunderstandin g how it should work, or am i doing this wrong.

thanks for any help

Peted
Aug 27 '07 #4
On Mon, 27 Aug 2007 09:19:33 +0200, "Alexander" <no@email.comwr ote:
>Hi,

If the comma should be a delimiter, isn't it just possible to split the
string:

String[] temp =
ConfigurationM anager.AppSetti ngs.GetValues(" rdbUser1Cpu1"). ToString().Spli t(',');

- Alexander
I dont know why i didnt think of that, i will try it

thanks

Peted

Aug 27 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6959
by: Thomas Guettler | last post by:
Hi, I need a config like this: ignore=".*/foodir/.*\.pyc" ignore=".*/foodir/.*~" .... The ConfigParser of the standard library can't handle this,
17
43955
by: Roland Hall | last post by:
Is there a way to return multiple values from a function without using an array? Would a dictionary object work better? -- Roland Hall /* This information is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. */ Technet Script Center - http://www.microsoft.com/technet/scriptcenter/ WSH 5.6 Documentation -...
4
27238
by: Aaron | last post by:
can a method return multiple values? pseudo code public string method1() { //db pull select col1, col2, from tb1 s1 = col1;
16
17411
by: Nikolay Petrov | last post by:
How can I return multiple values from a custom function? TIA
9
10915
by: Karl O. Pinc | last post by:
I want to return multiple values, but not a set, only a single row, from a plpgsql function and I can't seem to get it to work. (I suppose I'd be happy to return a set, but I can't seem to make that work either. Anyway, what's wrong with this?) Version is: $ rpm -q postgresql
5
10089
by: mctime | last post by:
Hello, I am attempting to split a raw data table into a new table that has split out a specific field in the raw data and created a new record for each split but I have come to an impasse due to my limited knowledge of sql. The Raw data contains a number of columns with key columns similar to Name, Product and Partcode. The issue is that the Partcode column in the raw data can contain multiple values split by either a "," or a
6
4165
by: Pippen | last post by:
Hi, I'm trying to read all the selected items in a ListBox. So after the user selects the values they want in the ListBox they select a button. This is where I want to put into a string all the values that were selected. The ListBox is populated by a stored proc that reads a DB table. Yes, I have the SelectionMode property set to MultiExtended, I have also tried MultiSimple. I have seen some examples for ASP Web forms but I'm using...
5
7898
by: unknown418 | last post by:
I am confused what is the efficient way to read in a file with multiple values per line. Each value is separated by a space character. The values could be characters or real values. I am using ifstream to get the file by passing it a c string as the filename but I am using a c++ string to get each line with getline(). But to get the individual values I think the only way is to use strtok() which needs a c string as input. To convert a...
0
1178
by: =?Utf-8?B?c2l4c2NodWx0eno=?= | last post by:
does anyone have an idea how to conditional format for multiple values in an access report?
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10091
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8972
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.