0

I have simple application. To be more specific this is Visual Studio Addin. Client needs to specify several settings (string, int, decimal etc)

I need to be able to load it at starup time and save if changed.

Let's say for simplicity I have all settings in one class AppSettings.

I can of course use DataContractSerializer to serialize/deserialize AppSettings but I think there must be some standard way.

Captain Comic
  • 15,744
  • 43
  • 110
  • 148

3 Answers3

1

I'm a huge fan of flat file storage myself, for example INI files. An article with example code on how to use INI files with .NET can be found here.

orlp
  • 112,504
  • 36
  • 218
  • 315
  • It assumes extra work - interop. INI files are not supported by .NET – Captain Comic Jan 13 '11 at 13:59
  • 1
    Yes, because Microsoft is _trying_ to move away from them. I'm not sure on how the information is stored, but some sites suggest it's XML. I truly detest XML. It's a markup language FFS! – orlp Jan 13 '11 at 14:05
1

There are Application Settings from Microsoft:

http://msdn.microsoft.com/en-us/library/a65txexh.aspx?appId=Dev10IDEF1&l=EN-US&k=k(APPLICATIONSETTINGSOVERVIEW);k(TargetFrameworkMoniker-%22.NETFRAMEWORK&k=VERSION=V4.0%22)&rd=true

You can use it like this:

Properties.Settings.Default.DumpHeader = dumpHeader;
Properties.Settings.Default.DumpFooter = dumpFooter;

Properties.Settings.Default.Save();

And loading works similar. But you have to define a .settings file first. It's from the WPF Framework, not sure if it works for WinForms too.

Similar question with a similar answer:
Best practice to save application settings in a Windows Forms Application

Community
  • 1
  • 1
Remy
  • 12,555
  • 14
  • 64
  • 104
1

Visual Studio Addin is specific case. In this case we can distribute only a .dll file which contain add in code and some .xml with Add-in definition if you want to use standard installation Add-In package. When I had such problem I try to resolve it with Windows registry. You can find a lot of examples how to deal with Windows registry in c#.

apros
  • 2,848
  • 3
  • 27
  • 31