Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Working with Setting config file VS 2010

Posted on 2011-09-04
8
Medium Priority
?
506 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
8 Comments
 
LVL 7

Assisted Solution

by:Gewgala
Gewgala earned 150 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
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!

 
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 150 total points
ID: 36506436
0
 
LVL 41

Accepted Solution

by:
graye earned 1200 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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

916 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