How do I access the Properties namespace from within a console app?
Solution 1
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.
Solution 2
- 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;
.
Nick
Software developer in the Boise, Idaho area. Interests: C#, C\C++, Objective-C Client-side scripting Design architecture, Patterns
Updated on July 05, 2020Comments
-
Nick almost 4 years
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 almost 15 yearsThe 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?
-
barneymc about 10 yearsMyProjectName.Settings1.Default.DatabaseConnectionString should give you access to the Settings file.
-
Lydon almost 6 yearsThat's a dead link
-
Thomas Adrian over 2 yearsin VS2022 the settingsfile is now a resource file