I want a configuration file in my .net core 3.1 winforms project. I have the following working to read the file
using Microsoft.Extensions.Configuration;
using System;
using System.Text;
using System.Windows.Forms;
using System.Xml;
namespace FeedRead
{
public partial class Form1 : Form
{
private ConfigurationBuilder configuration;
public Form1()
{
configuration = new ConfigurationBuilder();
configuration.SetBasePath(System.IO.Directory.GetCurrentDirectory());
configuration.AddJsonFile(path: "appsettings.json", optional: false, reloadOnChange: true);
configuration.Build();
}
but how do I save the configuration when I have made changes?
I tried the following but don't know how to complete it.
private void Form1_FormClosing(object sender, System.Windows.Forms.FormClosingEventArgs e)
{
configuration.Properties.Add("col1Width", listView1.Columns[0].Width);
var extn = configuration as Microsoft.Extensions.Configuration.IConfigurationBuilder; // not sure about
var provider = extn.GetFileProvider();
var info = provider.GetFileInfo(subpath: "appsettings.json"); // not sure about
// how do i save?
}