You can't change the app config file location since the behavior is managed by the .NET Framework internally.
But you can create your own configuration file and manage parameters with a hand-made singleton class that can be serialized in xml or binary format where you want to put it.
Example:
using System.Xml.Serialization;
[Serializable]
public class AppSettings
{
// The singleton
static public AppSettings Instance { get; private set; }
static public string Filename { get; set; }
static AppSettings()
{
Instance = new AppSettings();
}
// The persistence
static public void Load()
{
if ( !File.Exists(Filename) )
return;
using ( FileStream fs = new FileStream(Filename, FileMode.Open, FileAccess.Read) )
Instance = (AppSettings)new XmlSerializer(typeof(AppSettings)).Deserialize(fs);
}
static public void Save()
{
using ( FileStream fs = new FileStream(Filename, FileMode.Create, FileAccess.Write) )
new XmlSerializer(Instance.GetType()).Serialize(fs, Instance);
}
// The settings
public bool IsFirstStartup { get; set; } = true;
public string ExportPath { get; set; }
}
The test:
static void Test()
{
AppSettings.Filename = "c:\Test\AppSettings.xml";
AppSettings.Load();
if ( AppSettings.Instance.IsFirstStartup )
{
AppSettings.Instance.IsFirstStartup = false;
AppSettings.Instance.ExportPath = "c:\Test\Export";
AppSettings.Save();
Console.WriteLine("App initialized.");
}
else
{
Console.WriteLine("Welcome back.");
}
}
It needs to add System.Runtime.Serialization
assembly reference in the project file.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…