Saving and Restoring Program Settings

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I am writing a WM app where I want to save the settings the user created and
restore them on the next execution.

I would also like the settings to be saved / restored by Activesync.

Any ideas?

Thx.
 
Save them to a file or the registry. There's no magic "save all settings"
method that exists.

-Chris
 
PWF said:
Hi,

I am writing a WM app where I want to save the settings the user created and
restore them on the next execution.

I would also like the settings to be saved / restored by Activesync.

Any ideas?
I wrote a simple registry class for my purposes which might be of
help:

using Microsoft.Win32;
public class C4BRegistry
{
// The name of the key must include a valid root.
const string app = "MyApp";
const string subkey = "Software\\My Company\\" + app;
RegistryKey regKey, regSubKey;

public void WriteStringValue(string key, string value)
{
regKey = Registry.CurrentUser;
regSubKey = regKey.CreateSubKey(subkey);
regSubKey.SetValue(key, value, RegistryValueKind.String);
}

public void WriteNumericValue(string key, int value)
{
regKey = Registry.CurrentUser;
regSubKey = regKey.CreateSubKey(subkey);
regSubKey.SetValue(key, value, RegistryValueKind.DWord);
}

public string GetStringValue(string key, string def)
{
regKey = Registry.CurrentUser;
regSubKey = regKey.CreateSubKey(subkey);
return regSubKey.GetValue(key, def).ToString();
}

public string[] GetMultipleStringValue(string key)
{
regKey = Registry.CurrentUser;
regSubKey = regKey.CreateSubKey(subkey);
return (string[])regSubKey.GetValue(key, new string[] { "",
"" });
}

public int GetNumericValue(string key, int def)
{
regKey = Registry.CurrentUser;
regSubKey = regKey.CreateSubKey(subkey);
return (int)regSubKey.GetValue(key, def);
}
}

and it is used like this:

// Get settings from Registry
if (oReg.GetStringValue("Device ID", "").Length == 0)
{
oReg.WriteStringValue("Device ID", Did.GetDeviceId);
}

Hope this helps...


Will Chapman
 
Many thanks, I'll give both a thought.

Of course I would like activesync to save the settings to the desktop, but
after giving the docs a quick look this appears to be quite a task.

If I save to a file, can I somehow per my application register the file for
synchronisation?

Thanks,
PWF


Will Chapman" <"nbquidditch said:
PWF said:
Hi,

I am writing a WM app where I want to save the settings the user created and
restore them on the next execution.

I would also like the settings to be saved / restored by Activesync.

Any ideas?
I wrote a simple registry class for my purposes which might be of
help:

using Microsoft.Win32;
public class C4BRegistry
{
// The name of the key must include a valid root.
const string app = "MyApp";
const string subkey = "Software\\My Company\\" + app;
RegistryKey regKey, regSubKey;

public void WriteStringValue(string key, string value)
{
regKey = Registry.CurrentUser;
regSubKey = regKey.CreateSubKey(subkey);
regSubKey.SetValue(key, value, RegistryValueKind.String);
}

public void WriteNumericValue(string key, int value)
{
regKey = Registry.CurrentUser;
regSubKey = regKey.CreateSubKey(subkey);
regSubKey.SetValue(key, value, RegistryValueKind.DWord);
}

public string GetStringValue(string key, string def)
{
regKey = Registry.CurrentUser;
regSubKey = regKey.CreateSubKey(subkey);
return regSubKey.GetValue(key, def).ToString();
}

public string[] GetMultipleStringValue(string key)
{
regKey = Registry.CurrentUser;
regSubKey = regKey.CreateSubKey(subkey);
return (string[])regSubKey.GetValue(key, new string[] { "",
"" });
}

public int GetNumericValue(string key, int def)
{
regKey = Registry.CurrentUser;
regSubKey = regKey.CreateSubKey(subkey);
return (int)regSubKey.GetValue(key, def);
}
}

and it is used like this:

// Get settings from Registry
if (oReg.GetStringValue("Device ID", "").Length == 0)
{
oReg.WriteStringValue("Device ID", Did.GetDeviceId);
}

Hope this helps...


Will Chapman
 
Save it to My Documents.


PWF said:
Many thanks, I'll give both a thought.

Of course I would like activesync to save the settings to the desktop, but
after giving the docs a quick look this appears to be quite a task.

If I save to a file, can I somehow per my application register the file
for
synchronisation?

Thanks,
PWF


Will Chapman" <"nbquidditch said:
PWF said:
Hi,

I am writing a WM app where I want to save the settings the user
created and
restore them on the next execution.

I would also like the settings to be saved / restored by Activesync.

Any ideas?
I wrote a simple registry class for my purposes which might be of
help:

using Microsoft.Win32;
public class C4BRegistry
{
// The name of the key must include a valid root.
const string app = "MyApp";
const string subkey = "Software\\My Company\\" + app;
RegistryKey regKey, regSubKey;

public void WriteStringValue(string key, string value)
{
regKey = Registry.CurrentUser;
regSubKey = regKey.CreateSubKey(subkey);
regSubKey.SetValue(key, value, RegistryValueKind.String);
}

public void WriteNumericValue(string key, int value)
{
regKey = Registry.CurrentUser;
regSubKey = regKey.CreateSubKey(subkey);
regSubKey.SetValue(key, value, RegistryValueKind.DWord);
}

public string GetStringValue(string key, string def)
{
regKey = Registry.CurrentUser;
regSubKey = regKey.CreateSubKey(subkey);
return regSubKey.GetValue(key, def).ToString();
}

public string[] GetMultipleStringValue(string key)
{
regKey = Registry.CurrentUser;
regSubKey = regKey.CreateSubKey(subkey);
return (string[])regSubKey.GetValue(key, new string[] { "",
"" });
}

public int GetNumericValue(string key, int def)
{
regKey = Registry.CurrentUser;
regSubKey = regKey.CreateSubKey(subkey);
return (int)regSubKey.GetValue(key, def);
}
}

and it is used like this:

// Get settings from Registry
if (oReg.GetStringValue("Device ID", "").Length == 0)
{
oReg.WriteStringValue("Device ID", Did.GetDeviceId);
}

Hope this helps...


Will Chapman
 
Back
Top