I was trying to find a way to use appdata path as my environment.currentdurectory which means I want to run the c# application from appdata folder and in my project I always used environment.currentdirectory.
I couldn't find a way that I can set appdata path in app config and later replace environment.curentdirectory by appdata path...
PS:.
1) I want to set my programs data path as appdata
2) my project code is set to use environment.currentdirectory
3) I don't want to replace environment.currentdirectory by going each line by line
Target .Net framework 4
Have you tried doing this via the app domain.
See:
https://learn.microsoft.com/en-us/dotnet/api/system.appdomain.basedirectory?view=netframework-4.7.2
// Create application domain setup information
var domaininfo = new AppDomainSetup();
domaininfo.ConfigurationFile = System.Environment.CurrentDirectory +
Path.DirectorySeparatorChar +
"ADSetup.exe.config";
domaininfo.ApplicationBase = System.Environment.CurrentDirectory;
//Create evidence for the new appdomain from evidence of the current application domain
Evidence adEvidence = AppDomain.CurrentDomain.Evidence;
// Create appdomain
AppDomain domain = AppDomain.CreateDomain("Domain2", adEvidence, domaininfo);
// Display application domain information.
Console.WriteLine("Host domain: " + AppDomain.CurrentDomain.FriendlyName);
Console.WriteLine("Child domain: " + domain.FriendlyName);
Console.WriteLine();
Console.WriteLine("Configuration file: " + domain.SetupInformation.ConfigurationFile);
Console.WriteLine("Application Base Directory: " + domain.BaseDirectory);
AppDomain.Unload(domain);