# Load and Save Rules

Rules Manager supports loading and saving rules. Learn more about loading and saving rules in an XML file in RulesManager documentation.

## Content

Rules Manager supports loading and saving rules to an XML file. It allows you to load rules definition using [LoadRules ](/componentone/api/win/online-rulesmanager/dotnet-framework-api/C1.Win.RulesManager.4.8/C1.Win.RulesManager.C1RulesManager.LoadRules.html)method of the [C1RulesManager](/componentone/api/win/online-rulesmanager/dotnet-framework-api/C1.Win.RulesManager.4.8/C1.Win.RulesManager.C1RulesManager.html) class. The **LoadRules** method provides three overloads to load rules definition from an XML file, XMLReader or a stream. Similarly, RulesManager lets you save the rules definition using [SaveRules](/componentone/api/win/online-rulesmanager/dotnet-framework-api/C1.Win.RulesManager.4.8/C1.Win.RulesManager.C1RulesManager.SaveRules.html) method of the **C1RulesManager** class. The **SaveRules** method provides three overloads which can be used to save rules definition to an XML file, XMLWriter or a stream.

The following example demonstrates the use of the LoadRules to load the rules definition from an XML file and the SaveRules methods to save the rules definition in an XML file when any rule is changed in the Rules Manager. This example uses the same data source which is configured in [Quick Start](/componentone/docs/win/online-rulesmanager/quick-start).

```csharp
private const string xmlFileName = "LoadRules.xml";
private string pathToXmlFile = null;
private void ApplyRules()
{
    pathToXmlFile = Path.Combine(Directory.GetCurrentDirectory(), xmlFileName);
    if (!File.Exists(pathToXmlFile))
    {
        ApplyPredefinedRules();
    }
    else
    {
        //Load rules definition from the XML file
        rulesManager.LoadRules(pathToXmlFile);
    }
}
private void RulesManager_RulesChanged(object sender, ListChangedEventArgs e)
{
    //Save rules definition to the XML file
    rulesManager.SaveRules(pathToXmlFile);
}
```