tags:

views:

33

answers:

3

hi. in C# 3.5 (VS 2008) , how can i have a Resourse file or something like that, to have some of my config strings like webservice URLs that i can change them at runtime? because of some reasons , i don't want it to be in app.config file. here is the sample code that i like to have:

string s = Resource1.myURL;
A: 

Use a settings class

Gerrie Schenck
setting file contents will be copied into app.config, and i can't see the independent setting file.
+1  A: 

Why can't? Just right click your project then Add Items->General->Resource File. Say you may have several resource files such as Resource.en-US.resx, Resource.zh-CN.resx and Resource.de-DE.resx. To manage these resources, you are supposed to have a class called ResourceManager which probably contains these methods:

public static GetResource(CultureInfo culture, string key)
{
    //blabla
}

The ResourceManager is well initialized at the beginning of the application (for example, it's initialized in Global.asax if you are using asp.net webform), storing in the application cache.

Danny Chen
A: 

If you don't want to use app.config then simply make your own XML settings file. After all app.config is nothing more than that. You can customize it to the format that you want, and only inlcude the tags you need. Once it is finished you can than use LINQ to XML to parse through and change things as needed. If you are not familiar with linq than it might take a couple minutes of reading, but I think it would be well worth it.

Adkins