Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

app.config files..

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chizl - 06 Mar 2008 02:24 GMT
I can read .config files all day, but for some reason I cant write to them..
After searching for a few days, there are some that have code showing to
write, but none of them seem to work.    Someone explain to me what could be
the problem?

I'm admin of the machine, I'm writting local, and this is the code I've
tried..

Way #1
--------------
Configuration config;
config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings[strKey].Value = strValue;     //error, Object
reference not set to an instance of an object
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");

Way #2
--------------
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
ConfigurationManager.AppSettings.Add(strKey, strValue);        //error,
config is readonly..  But it's not..
ConfigurationManager.RefreshSection("appSettings");
dlm@bypsoft - 06 Mar 2008 17:35 GMT
Hi,

we are performing such a tasks with the following:
string sPath = System.IO.Path.Combine(Environment.CurrentDirectory,
"your_exe_name.exe");

Configuration config = ConfigurationManager.OpenExeConfiguration(sPath);

config.AppSettings.Settings["test_key"].Value = "test_value";

config.Save(ConfigurationSaveMode.Modified);

If your <appSettings> section doesn't contain "test_key" you should add it
first (othewise you get null reference exception)

config.AppSettings.Settings.Add("test_key", "test_value");

and than save it.

This should work.

Regards,

dlm@bypsoft
Compare database schema and data on SQL Server, MySQL, Oracle for free
www.bypsoft.com

>I can read .config files all day, but for some reason I cant write to
>them.. After searching for a few days, there are some that have code
[quoted text clipped - 20 lines]
> config is readonly..  But it's not..
> ConfigurationManager.RefreshSection("appSettings");
Chizl - 20 Mar 2008 01:02 GMT
Is this too hard of a question or not worth anyones time?

>I can read .config files all day, but for some reason I cant write to
>them.. After searching for a few days, there are some that have code
[quoted text clipped - 20 lines]
> config is readonly..  But it's not..
> ConfigurationManager.RefreshSection("appSettings");
Peter Duniho - 20 Mar 2008 02:30 GMT
> Is this too hard of a question or not worth anyones time?

I suspect it's more to do with the vague nature in which you asked your  
question.  On occasion, someone will take some time to try to help someone  
work through their question, to try to make it more clear and specific so  
that it's possible to answer.

But often times, a poorly-asked question just goes unanswered.  Such is  
life.  It's a good reason to learn to ask better questions.

Pete

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.