11

I am trying to store/retrieve a value that is stored in the Application Settings. From within my console application I can not seem to access the Properties.Setting namespace. My web surfing has revealed that a little more work might be needed to do this from within a Console application. How does one do this?

string test = Properties.Settings.Default.MyString;

Thanks!

Nick
  • 19,198
  • 51
  • 185
  • 312

3 Answers3

20

By default there is no Settings file in a Console application. However, you can add one simply by right-clicking your project in the solution explorer, choosing "Properties" and then in the resulting window, click the "Settings" tab.

There should be a link saying "Click here to create a default settings file". Once that's created, you're off to the races.

womp
  • 115,835
  • 26
  • 236
  • 269
  • The settings tab doesn't a "Click here to create a default settings file" link. But I can "View Code" which takes me to a settings.cs file. There are some event handlers that need to be wired up. Does anyone know of a good example of hoe this is done? – Nick May 11 '09 at 22:57
  • MyProjectName.Settings1.Default.DatabaseConnectionString should give you access to the Settings file. – barneymc Mar 12 '14 at 10:35
  • 1
    in VS2022 the settingsfile is now a resource file – Thomas Adrian Nov 02 '21 at 11:42
4
  1. Ensure the namespace of the class you're using is the default namespace of your project.

2.then you cna use

string s = Properties.Settings.Default.THENAMEINSETTINGS;

.

enter image description here

yu yang Jian
  • 6,680
  • 7
  • 55
  • 80
0

So.. Once I created my Settings.settings file in the project that is saving the property I ran into the issue of how to access these properties from another project in the same solution. The settings object is sealed so you have to use a little trickery to gain access to the property values in another project. I found my solution here:

http://blog.decarufel.net/2007/10/getting-access-to-settings-in-another.html

Basically you create a link file to the Settings.Designer.cs file in the project where you are trying to retrieve the values.

I hope this helps someone with a similar issue.

-Nick

Nick
  • 19,198
  • 51
  • 185
  • 312