From f9062cbbfa873af1e7840786dd982ac3a2182be4 Mon Sep 17 00:00:00 2001 From: Dinesh Solanki <15937452+DineshSolanki@users.noreply.github.com> Date: Thu, 3 Sep 2020 18:46:46 +0530 Subject: [PATCH] Fixed appSetting.json not updating because of path issue when starting from another location Path.GetCurrentDirectory() was misunderstood. changed to Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) --- BatchMuxer_SubEd_Console/classes/util.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/BatchMuxer_SubEd_Console/classes/util.cs b/BatchMuxer_SubEd_Console/classes/util.cs index 10ec090..e64f762 100644 --- a/BatchMuxer_SubEd_Console/classes/util.cs +++ b/BatchMuxer_SubEd_Console/classes/util.cs @@ -4,6 +4,7 @@ using System.Diagnostics; using System.IO; using System.Linq; +using System.Reflection; namespace BatchMuxer_SubEd_Console.Classes {/// @@ -105,6 +106,7 @@ public static bool RenameFile(FileInfo[] fi) return hasRenamed; } + /// /// Update appsetting.json /// @@ -112,13 +114,15 @@ public static bool RenameFile(FileInfo[] fi) /// new value public static void WriteToConfig(string key, string value) { - string json = File.ReadAllText("appsettings.json"); + string appSettingPath = + Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "appsettings.json"); + string json = File.ReadAllText(appSettingPath); var application = new Application(); JsonConvert.PopulateObject(json, application); dynamic jsonObj = JsonConvert.DeserializeObject(json); jsonObj["application"][key] = value; string output = Newtonsoft.Json.JsonConvert.SerializeObject(jsonObj, Formatting.Indented); - File.WriteAllText("appsettings.json", output); + File.WriteAllText(appSettingPath, output); } } } \ No newline at end of file