user3468577
user3468577

Reputation: 1

Windows Forms User Settings in C# getting lost

I want to save settings permanently in the exe file

I use this code

Settings.Default.WindowSize = this.Size;

Settings.Default.Save();

I'm having one big problem with this if the file path change all settings are lost. Like if you have the exe on a flash drive and you put it in different PC the settings is gone.

Is there a way around this. OR is there a different setting/parameter I can use?

Upvotes: 0

Views: 342

Answers (2)

Neil N
Neil N

Reputation: 25258

You could use the registry, but that only helps when you move the EXE on a single machine. Best thing is Luann's answer, copy the accompanying config file.

A purely transportable EXE would store it's settings "in the cloud"

Upvotes: 0

Luaan
Luaan

Reputation: 63722

You can't save settings in an exe file. Settings.Default.Save() doesn's save settings into an exe file. That's what configuration files are for. If you want to bring the settings with you, copy the configuration file as well.

Of course, saving configuration next to exe files is outdated, and considered bad practice, not to mention being insecure (and Vista+ will not allow you to do it without administrator privileges inside of Program files). The configuration will endup in your user folder, so that it doesn't affect other users of the application.

Upvotes: 2

Related Questions