473,378 Members | 1,110 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Using Settings across an application C# 2.0

I currently use statements like this in my 1.1 code.

System.Configuration.ConfigurationSettings.AppSett ings[ "jobclock.net" ]

I use this in DLLs that are referenced by the application. The application
has this data in its app.config file. I would like to switch to the new
Setting files in 2.0, but I don't know if I can access these settings from a
different DLL. I can't make a reference in the DLL back to the application
because that would create a circular reference.

Anyone done this or have any ideas?

Thanks,

Eric Renken


Dec 27 '05 #1
13 1841
Eric,

What do you have to set a reference back to the application for? The
line that you referenced in your post is from the ConfigurationSettings
class in the System.Configuration namespace, and the dll that is in
certainly doesn't have a reference to your dll, so there should be no
problem.

I don't see why you would have to change this. If your DLL is loaded,
you can access the settings in the file the same as any other assembly
running in the app domain.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Eric Renken" <Er*********@newsgroup.nospam> wrote in message
news:uc**************@tk2msftngp13.phx.gbl...
I currently use statements like this in my 1.1 code.

System.Configuration.ConfigurationSettings.AppSett ings[ "jobclock.net" ]

I use this in DLLs that are referenced by the application. The
application has this data in its app.config file. I would like to switch
to the new Setting files in 2.0, but I don't know if I can access these
settings from a different DLL. I can't make a reference in the DLL back
to the application because that would create a circular reference.

Anyone done this or have any ideas?

Thanks,

Eric Renken

Dec 27 '05 #2
Right I don't have to set a reference back for using
ConfirationSettings.AppSettings[], but the problem is that method is
obsolete in 2.0 and I am trying to use 2.0 settings file now and I want to
know how to use the settings from my EXE in a DLL that is referenced by the
EXE without passing that data to it.

Eric Renken

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:el**************@TK2MSFTNGP11.phx.gbl...
Eric,

What do you have to set a reference back to the application for? The
line that you referenced in your post is from the ConfigurationSettings
class in the System.Configuration namespace, and the dll that is in
certainly doesn't have a reference to your dll, so there should be no
problem.

I don't see why you would have to change this. If your DLL is loaded,
you can access the settings in the file the same as any other assembly
running in the app domain.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Eric Renken" <Er*********@newsgroup.nospam> wrote in message
news:uc**************@tk2msftngp13.phx.gbl...
I currently use statements like this in my 1.1 code.

System.Configuration.ConfigurationSettings.AppSett ings[ "jobclock.net" ]

I use this in DLLs that are referenced by the application. The
application has this data in its app.config file. I would like to switch
to the new Setting files in 2.0, but I don't know if I can access these
settings from a different DLL. I can't make a reference in the DLL back
to the application because that would create a circular reference.

Anyone done this or have any ideas?

Thanks,

Eric Renken


Dec 28 '05 #3
Hi Eric,

As far as I know, we cannot get the app setting in the DLL if it is
referenced by an EXE. You have to pass the setting from .EXE to the DLL and
save it in a static variable. When calling the method that needs the
setting, we can pass it as an argument or let the method get directly from
the static variable.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Dec 29 '05 #4
OK, then I really don't like that you are phasing out the old way of doing
this, because with the old way all the DLLs used the config file of the
application that instantiated them when you called
ConfigurationSettings.AppSettings[]. I think this new way has really
limited that. I had some classes that exposed static methods of data stored
int he config file, but those will now have to change because that was in a
common DLL not in the EXE.

Like I have a exception handler that post to a web site and it used to pull
that data out of a config file. Now I have to make sure when the exception
handler gets called that I pass in the web address; where before I could
just pull this once now I have to load it multiple times because I don't
know where it is going to be called from first.

Looks like I will stay with the old way until my code breaks.

I was hoping for a way to call the global:: directly and have to get the
data from the config file.

Eric Renken
"Kevin Yu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:bk*************@TK2MSFTNGXA02.phx.gbl...
Hi Eric,

As far as I know, we cannot get the app setting in the DLL if it is
referenced by an EXE. You have to pass the setting from .EXE to the DLL
and
save it in a static variable. When calling the method that needs the
setting, we can pass it as an argument or let the method get directly from
the static variable.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Dec 30 '05 #5
Hi Eric,

Apologize that I have made a mistake in my last post. We can read from an
app.config file from the DLL is it is referenced by an EXE. Because
app.config is per appdomain. If the dll is loaded into the same appdomain
as the exe, it will surely to access the app.config file.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Dec 30 '05 #6
OK, how do I do this? Using the new style, where the data is in a Settings
file (when you make the setting Application specific it stores it in the
app.config)

Eric Renken

"Kevin Yu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:$Z**************@TK2MSFTNGXA02.phx.gbl...
Hi Eric,

Apologize that I have made a mistake in my last post. We can read from an
app.config file from the DLL is it is referenced by an EXE. Because
app.config is per appdomain. If the dll is loaded into the same appdomain
as the exe, it will surely to access the app.config file.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jan 2 '06 #7
Hi Eric,

In .NET 1.1, we use ConfigurationSettings class to get all the settings
from app.config. In .NET 2.0 it's better to use ConfigurationManager class
to achieve this. For example, you have an app.config file like

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="AppSetting0" value="Monday, February 28, 2005 1:27:59 PM" />
<add key="AppSetting1" value="Monday, February 28, 2005 1:36:40 PM" />
</appSettings>
</configuration>

You can use the following to get settings.

public static string m1()
{
return
System.Configuration.ConfigurationManager.AppSetti ngs["AppSetting0"];
}

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jan 3 '06 #8
OK, ConfigurationManager, thanks.

Eric Renken
"Kevin Yu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:wJ**************@TK2MSFTNGXA02.phx.gbl...
Hi Eric,

In .NET 1.1, we use ConfigurationSettings class to get all the settings
from app.config. In .NET 2.0 it's better to use ConfigurationManager class
to achieve this. For example, you have an app.config file like

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="AppSetting0" value="Monday, February 28, 2005 1:27:59 PM" />
<add key="AppSetting1" value="Monday, February 28, 2005 1:36:40 PM" />
</appSettings>
</configuration>

You can use the following to get settings.

public static string m1()
{
return
System.Configuration.ConfigurationManager.AppSetti ngs["AppSetting0"];
}

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jan 3 '06 #9
You're welcome.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jan 4 '06 #10
Well this is interesting, because we have a System.Configuration namespace
in System, but to use Configuration you must add the System.Configuration
Reference.

Eric Renken

"Kevin Yu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:wJ**************@TK2MSFTNGXA02.phx.gbl...
Hi Eric,

In .NET 1.1, we use ConfigurationSettings class to get all the settings
from app.config. In .NET 2.0 it's better to use ConfigurationManager class
to achieve this. For example, you have an app.config file like

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="AppSetting0" value="Monday, February 28, 2005 1:27:59 PM" />
<add key="AppSetting1" value="Monday, February 28, 2005 1:36:40 PM" />
</appSettings>
</configuration>

You can use the following to get settings.

public static string m1()
{
return
System.Configuration.ConfigurationManager.AppSetti ngs["AppSetting0"];
}

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jan 4 '06 #11
Hi Eric,

Although System.Configuration namespace is a subnamespace under System,
they are implemented in different assemblies. So if you wish to use the
System.Configuration namespace, you have to add reference to that assembly.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jan 5 '06 #12
Never had to add it before I started using the new command.

Eric Renken

"Kevin Yu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:G6*************@TK2MSFTNGXA02.phx.gbl...
Hi Eric,

Although System.Configuration namespace is a subnamespace under System,
they are implemented in different assemblies. So if you wish to use the
System.Configuration namespace, you have to add reference to that
assembly.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jan 12 '06 #13
OK... So this is what I did:

- I went to the properties screen of my project and created for
newapplication settings in the 'Settings' tab/section. These are named:
InitalBrowseFolder, ECopyAppPath, RootSaveFolderPath and RootSaveFolder.
-The first three are string types, the last one is of type
System.Environment+SpecialFolder
-All four settings are in the User scope (As I read that settings that are
put in the Application Scope will be read only,correct?)
- I created default values for each setting; I made the first 3 defults c:\
and the last one says MyComputer.

Ok... so I want these settings to persist for the user indefinitely. They
can be changed by the user. The first step if that I want to be able to read
them, and its been really frustrating finding the correct way to do this.
Please improve documentation for this fequently used feature! Anyway...
based on what I've read so far I tried the following:

- I referenced the System.Configuration class, and triues accessing the
ECopyAppPath by using the statement:
ConfigurationManager.AppSettings["ECopyAppPath"] ...it returns null. grrr.

- I also tried instantiating the ApplicationsSettingsBase class:
private ApplicationSettingsBase settings;
...
...
string x = settings.Properties["ECopyAppPath"].ToString();

.... this also returns null.

What am I doing wrong? Are the settings in the wrong place or am I trying
to retrieve them improperly?

"Eric Renken" wrote:
Never had to add it before I started using the new command.

Eric Renken

"Kevin Yu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:G6*************@TK2MSFTNGXA02.phx.gbl...
Hi Eric,

Although System.Configuration namespace is a subnamespace under System,
they are implemented in different assemblies. So if you wish to use the
System.Configuration namespace, you have to add reference to that
assembly.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."


Jan 13 '06 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bob Altman | last post by:
How do I bind a value from My.Settings to a property on a control on a Windows form? I've created a setting called My.Settings.Value1 of type String. Now I want to create a "Settings" dialog...
0
by: Paul Evans | last post by:
I have an application which stores settings in a user file. This is because the application though being designed to be run by a single user will have the settings being updated on the fly, and...
2
by: =?Utf-8?B?QWFyb24=?= | last post by:
I am trying to create dynamic settings in a .NET 2.0 C# application. I need to be able to store settings on the user, but I do not know how many settings are necessary at design time because the...
5
by: Steve Barnett | last post by:
I added some user settings to my app which caused the Settings.settings to be generated etc... and all was well and lovely and the Sun was shining. Then I changed the version number of my...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.