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:
public class Settings
{
public string Var1 { get; set; }
public bool Var2 { get; set; }
}
Save settings
To save settings globally for your tool, use the method Save
of the singleton instance of SettingsManager
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
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:
Settings settings;
if (SettingsManager.Instance.TryLoad(typeof(SampleTool), out settings))
{
MessageBox.Show("Settings found!");
}
else
{
settings = new Settings();
}
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
Settings settings;
if (SettingsManager.Instance.TryLoad(typeof(SampleTool), out settings, ConnectionDetail.ConnectionId.ToString()))
{
MessageBox.Show("Settings found!");
}
else
{
settings = new Settings();
}