Solved

Working with Setting config file VS 2010

Posted on 2011-09-04
8
488 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 41

Expert Comment

by:graye
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:JSW21
Comment Utility
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
Comment Utility
0
 
LVL 41

Accepted Solution

by:
graye earned 400 total points
Comment Utility
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
Comment Utility
I will give it a try
Many thanks
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 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

10 Experts available now in Live!

Get 1:1 Help Now