Solved

Working with Setting config file VS 2010

Posted on 2011-09-04
8
498 Views
Last Modified: 2012-06-27
Hi

I am a bit confuse on how to use Setting to store my constant value in config file.

e.g. my.dll.config

In the setting there I can choose btw Application or User scope, also there is access modifer Internal/Public

my setting are Internal/Application

My goal is to allow my setting in VS2010 for easy programming such as
e.g.   string x = settings.Default.myconfig

and also allow my user of dll to change the value in my.dll.config file.

However, so far when user modify config file value - dll do not response to new setting

How can i solve the problem? Also, if i change my setting from Application to User scope - I am getting compiler error - though i have not try to fix it yet as I not so sure about the scope setting.
 
0
Comment
Question by:JSW21
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 7

Assisted Solution

by:Gewgala
Gewgala earned 50 total points
ID: 36481355
What you need to do is open up your resource file, and add a setting like you stated, let's say the setting is "BackupPath" and it has an Application scope.  In C# in the code behind, you do:

string path = Settings.Default.BackupPath;

when you want to change the value, you do:

Settings.Default.BackupPath = "some new value";

you then must also call the Save() method:

Settings.Default.Save();

If you do not call the Save() method your new value will not persist.
0
 
LVL 41

Expert Comment

by:graye
ID: 36481474
Hang on...  The concept of the Setting file was designed for EXE files, and not DLLs.

So, you have to be a bit creative to merge all of your settings for both the EXE and the DLL into a single *.exe.config file.

I usually just "pretend that it works" and follow the normal rules for creating and using the settings inside my DLL file.  Then when I'm done I use notepad to copy-n-paste that section of the app.config (from the DLL) that contains the settings that I created into the appropriate section of app.config of the EXE project.
0
 

Author Comment

by:JSW21
ID: 36503797
Actually my goal is to allow my user of the dll to change the config value in the .config file.

So I guess I would not change to value of file programatically.

However, you are right that in the end there will be exe file... and essentially exe.config file.
From your suggestion I can copy the text into the exe.config

Doing so can my user change the value from the file?
... are there particular ... way to do it?
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 41

Expert Comment

by:graye
ID: 36504302
Sure, your users will be able to make changes to the application's *.exe.config file (which will contain both EXE and DLL sections).

For example, let's say that your DLL has a setting for a connection string...  that connection string setting will appear in the application's config file.  Your users could use Notepad to edit the config file and change the connection string.
0
 

Author Comment

by:JSW21
ID: 36506014
graye,

Is it possible to that i add exact same config name in VS for both dll and exe.config?

so I dont have to copy and paste from dll.config to exe.config each time i create a new exe build?

0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 50 total points
ID: 36506436
0
 
LVL 41

Accepted Solution

by:
graye earned 400 total points
ID: 36506665
I don't think so...  I believe you're stuck with good 'ole copy-n-paste method for each project that uses that DLL
0
 

Author Closing Comment

by:JSW21
ID: 36600736
I will give it a try
Many thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question