Saving setting to a exe
Asked Answered
S

3

2

I have a program which I want to store information in a string. I have been using the Properties.Setting.Default.STRINGname to store the information, which works fine on my PC, and I can see the saved strings (when I go to the settings in the application). But when I take the application to a new PC it losses the strings. Is there a way to be able to edit this information and save it in the app? So basically I need to be able to convert the user setting to application setting, but after the runtime.

var settings = Properties.Settings.Default;
        settings.H1 = textbox1.text;
        settings.H2 = textbox2.text;

        settings.Save();
Searcy answered 24/4, 2012 at 19:26 Comment(1)
what .NET version are you developing for?Chaplain
C
5

MSDN explicit says something about this:

Settings that are application-scoped are read-only, and can only be changed at design time or by altering the .config file in between application sessions. Settings that are user-scoped, however, can be written at run time just as you would change any property value. The new value persists for the duration of the application session. You can persist the changes to the settings between application sessions by calling the Save method.

For this, Application setting will never work for you. However, if you are using a User scoped settings it does work, but soon you change the application from one computer to another (as you say you want to) you will loose the settings as that's another machine (another user-scope)...

There are way to continue to have the same settings, you can do, at least 2 things:

  • use a .config file to save the settings (it's an XML file)
  • use a service to host the settings and you can read if user has internet access

What you can't do is

  • using only one executable file, save the settings from computer to computer.
Chaplain answered 24/4, 2012 at 19:50 Comment(0)
C
0

User settings are compiled differently than Application settings, and thus cannot be converted after compilation. Why not compile with Application Settings?

Cholera answered 24/4, 2012 at 19:28 Comment(2)
Because i want to be able to add information or change it as i find things to add but with out recompiling the program each timeSearcy
You shouldn't have to recompile to change the settings... just modify your app.exe.config file...Cholera
S
0

The code you are using should save the user settings. Rememeber that user settings will be saved in the user's data folder. Not in the configuration file where the app was installed (say program files). This is the usual path:

<Profile Directory>\<Company Name>\<App Name>_<Evidence Type>_<Evidence Hash>\<Version>\user.config

See this links form more information

Shielashield answered 24/4, 2012 at 19:32 Comment(1)
...when I take the application to a new PC... - He wants to save the settings cross-computers...Chaplain

© 2022 - 2024 — McMap. All rights reserved.