How do I access the Properties namespace from within a console app?
Asked Answered
A

3

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!

Aquavit answered 11/5, 2009 at 22:43 Comment(0)
W
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.

Westbrook answered 11/5, 2009 at 22:53 Comment(3)
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?Aquavit
MyProjectName.Settings1.Default.DatabaseConnectionString should give you access to the Settings file.Erma
in VS2022 the settingsfile is now a resource fileGrunion
K
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

Kamila answered 4/7, 2016 at 13:41 Comment(0)
A
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

Aquavit answered 12/5, 2009 at 17:11 Comment(1)
That's a dead linkTobacco

© 2022 - 2024 — McMap. All rights reserved.