Solved

Working with Setting config file VS 2010

Posted on 2011-09-04
8
496 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
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 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

738 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