Solved

Working with Setting config file VS 2010

Posted on 2011-09-04
8
492 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 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
2 questions 10 25
get row value in vb.net 4 14
Help with exporting to excel 4 25
Older JQuery functionality is not in the newer JQuery 1.4.4 versions, 6 21
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

815 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now