none
missing app.config in vs2005

    Question

  • Hi,
    I'm wondering how can i open (or create) an appconfig in VS2005. As I remember, in VS2003 it was created with the project, but in VS 2005 it is not (or somehow it is hidden). How can I create/access it? (Or there is a new way in VS2005 to manage some settings?)
    Thanks
    Wednesday, February 07, 2007 1:28 AM

Answers

  • Hi,

    with VS2005, you can manage your settings through Project properties - when selected through menu or otherwise, select Settings tab and you'll probably see a "This project does not contain a default settings file. Click here to create one." link. Click that and you'll be able to define your application's settings, which will be available through your application; you'll be able to load them, save them and bind control's properties to them... Configuration file will be created too.

    Andrej

    Wednesday, February 07, 2007 2:05 AM
  • Hi

    You can use the Add->NewItem option to add a new app.config.

     

    Regards

    Wednesday, February 07, 2007 2:56 AM
  • If your using Application settings, created by VS, you can access them through Properties.Settings.Default class. Default instance class should expose all your settings as properties and you can enumerate all properties by accessing its Properties property.

    Andrej

    Wednesday, February 07, 2007 5:33 PM

All replies

  • Hi,

    with VS2005, you can manage your settings through Project properties - when selected through menu or otherwise, select Settings tab and you'll probably see a "This project does not contain a default settings file. Click here to create one." link. Click that and you'll be able to define your application's settings, which will be available through your application; you'll be able to load them, save them and bind control's properties to them... Configuration file will be created too.

    Andrej

    Wednesday, February 07, 2007 2:05 AM
  • Hi

    You can use the Add->NewItem option to add a new app.config.

     

    Regards

    Wednesday, February 07, 2007 2:56 AM
  • Ahh ok, and this settings file is a XMl document?

    Thanks for you two :)

     

    Wednesday, February 07, 2007 1:44 PM
  •  Oscarfh wrote:

    Ahh ok, and this settings file is a XMl document?

    Yes, the file which is created, is app.config, Visual Studio will just let you edit your settings through a data grid. Any settings you add/change in this grid will be stored in app.config, and Visual Studio will create a special Settings class, which will let you access those settings through its properties (you get intellisense and all).

    Of course, you can still add app.config file manually and do this "the old way", but you'd miss out on some cool new features...

    Andrej

    Wednesday, February 07, 2007 1:55 PM
  • Hi,

    sorry for bothering again, but I tried use the ConfigurationManager.AppSettings property but it returns a nameValueObject with 0 elements (I've inserted some elements in the app.config).

    What I am doing wrong?

     

    Thanks again

    Wednesday, February 07, 2007 3:27 PM
  • Hard to say without knowing how your app.config looks like. Did you insert settings through VS designer or write them directly to app.config [in the applicationSettings section]?

    Andrej

    Wednesday, February 07, 2007 4:33 PM
  • through the designer.

    I'm testing something I'm reading in a book.

    I created a console app, in the properties I clicked in "settings" and clicked in the link to create a new settings file.

    The VS2005 created a settings.settings file and the app.config. Using the designer (double click in the settings.settings file I inserted many inputs (names and values) using user and machine scope. Now I'm triyng to access it using this code:

     

    NameValueCollection appSettings =

    ConfigurationManager.AppSettings;

    string[] keys = appSettings.AllKeys;

    Console.WriteLine();

    Console.WriteLine("Application appSettings:");

    // Loop to get key/value pairs.

    for (int i = 0; i < appSettings.Count; i++) // but appSettings.Count is equal to 0!

    Console.WriteLine("#{0} Name: {1} Value: {2}",

    i, keysIdea, appSettingsIdea);

     

    but appSettings.Count is equal to 0.

     

    Thanks for your help

    Wednesday, February 07, 2007 4:45 PM
  • If your using Application settings, created by VS, you can access them through Properties.Settings.Default class. Default instance class should expose all your settings as properties and you can enumerate all properties by accessing its Properties property.

    Andrej

    Wednesday, February 07, 2007 5:33 PM
  • Ok, I'll use it :)

    Thanks a lot :)

    Thursday, February 08, 2007 11:34 AM
  • Hi

    You can try to use this http://msdn2.microsoft.com/en-us/library/aa730869(vs.80).aspx.

    I have tried to use the alternate set of settings but it did not seem to work for me, and the idea was very vague for me.

    I always preferred app.config than settings, and my own xml config file than app.config.

     

    Regards

    Friday, February 09, 2007 6:34 PM