473,387 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Properties.Settings NameValueCollection doesn't work?

For some unknown reason (user error?), I cannot get a NameValueCollection to
persist in the app.config file.

Unlike other settings, I cannot get the String Collection Editor GUI to
allow my to add/edit any values for a setting with type NameValueCollection.

Nor can I get a NameValueCollection to persist to the User Settings via code
using a simple C# Console App...

Is this a user error or ?

Thanks,
Rick
Here's the code behind:

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.Specialized;

namespace Play_With_Settings
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Starting...");

if (Properties.Settings.Default.MyNameValueCollection == null)
{
Properties.Settings.Default.MyNameValueCollection = new
NameValueCollection();
}

Console.WriteLine(Properties.Settings.Default.MyUs erSetting);

Console.WriteLine(Properties.Settings.Default.MyNa meValueCollection.Count);

Properties.Settings.Default.MyUserSetting = "Hello Saturn!";

Properties.Settings.Default.MyNameValueCollection. Add("name1",
"value1");
Properties.Settings.Default.MyNameValueCollection. Add("name2",
"value2");
Properties.Settings.Default.MyNameValueCollection. Add("name3",
"value3");

Properties.Settings.Default.Save();
Console.WriteLine(Properties.Settings.Default.MyNa meValueCollection.Count);
Console.WriteLine(Properties.Settings.Default.MyUs erSetting);

}
}
}

And now the app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings"
type="System.Configuration.ApplicationSettingsGrou p, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="Play_With_Settings.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
<sectionGroup name="userSettings"
type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="Play_With_Settings.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089"
allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<Play_With_Settings.Properties.Settings>
<setting name="MyValue" serializeAs="String">
<value>Hello World</value>
</setting>
</Play_With_Settings.Properties.Settings>
</applicationSettings>
<userSettings>
<Play_With_Settings.Properties.Settings>
<setting name="MyUserSetting" serializeAs="String">
<value>Hello Mars</value>
</setting>
<setting name="MyTest" serializeAs="Xml">
<value>
<ArrayOfString
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<string>x=y</string>
<string>1=2</string>
<string>a=b</string>
</ArrayOfString>
</value>
</setting>
</Play_With_Settings.Properties.Settings>
</userSettings>
</configuration>
Dec 15 '06 #1
0 2800

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

Similar topics

7
by: davidw | last post by:
I always use NameValueCollection. But I read an article says the only differece between Hashtable and NameValueCollection is that NameValueCollection could accept more than one value with same key?...
4
by: Steve Long | last post by:
Can anybody help me out with a code sample or other info on how to implement SyncRoot on a NameValueCollection? Or, is there another .NET class that does this for me with the same functionality as...
4
by: Hardy Wang | last post by:
Hi, I have a NameValueCollection, is it possible to bind this object to a two-column DataGrid? How to match columns? Thanks! -- WWW: http://hardywang.1accesshost.com ICQ: 3359839 yours...
0
by: Parag Mahajan | last post by:
Hi, I am using the membership provider class, "System.Web.Security.ActiveDirectoryMembershipProvider". I am using Login Server control and attaching the already configured...
2
by: DaTurk | last post by:
I have three interfaces, lets call them General, Client, Server. public interface General { public Value{get;} } public interface Client : General {}
13
by: Dave | last post by:
When using the properties designer to store application wide properties how do you get this to work across a project group containing an EXE and a collection of DLLs. I'm using C#.Net 2005. I...
7
by: Dom | last post by:
It seems I can't look at the Properties.Settings.Default.xxxx value in the immediate window while I'm in debug mode. If I try, I get the message: "'System.Windows.Forms.PropertyStore' does not...
2
by: Jan Eliasen | last post by:
Hi I am having some problems reading configuration values from a configuration file, using C# 2.0. I have programmed a Windows Service, and this part goes well - it runs nicely. Now, the...
0
by: =?Utf-8?B?RnV0cm9uaWNzIERldmVsb3Blcg==?= | last post by:
I am trying to store a collection of custom types in a Properties.Settings file which I will be updating at run time and saving on exit of the program. I understand how to use the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.