web
You’re offline. This is a read only version of the page.
close
XrmToolBox provides a SettingsManager class that allows you to save/load settings for your tool globally, or per connection (or any other criteria of your choice)

Create a settings class

Create a public class that will store your settings. This class must be serializable in XML.

Example:
  1. public class Settings
  2. {
  3. public string Var1 { get; set; }
  4. public bool Var2 { get; set; }
  5. }

Save settings

To save settings globally for your tool, use the method Save of the singleton instance of SettingsManager

  1. SettingsManager.Instance.Save(typeof(SampleTool), settings);

where SampleTool is your tool user control. The resulting saved file is MsCrmTools.SampleTool.xml.

If you want to save settings for a specific connection (or any other criteria), you can use the optional name argument

  1. SettingsManager.Instance.Save(typeof(SampleTool), settings, ConnectionDetail.ConnectionId.ToString());

The resulting saved file is MsCrmTools.SampleTool_8d1c9b43-883c-41d8-bce8-7219919ba3cf.xml.

Load settings 

To load global settings, use the method TryLoad of the singleton instance of SettingsManager

Example:
  1. Settings settings;
  2.  
  3. if (SettingsManager.Instance.TryLoad(typeof(SampleTool), out settings))
  4. {
  5.     MessageBox.Show("Settings found!");
  6. }
  7. else
  8. {
  9.     settings = new Settings();
  10. }
where SampleTool is your tool user control. 

To load settings for a specific connection, (or any other criteria), you can use the optional name argument
  1. Settings settings;
  2.  
  3. if (SettingsManager.Instance.TryLoad(typeof(SampleTool), out settings, ConnectionDetail.ConnectionId.ToString()))
  4. {
  5. MessageBox.Show("Settings found!");
  6. }
  7. else
  8. {
  9. settings = new Settings();
  10. }​​​​​​​