C# – How to update appsettings.json programmatically

You have to overwrite the appsettings.json file to be able to update values programmatically. You have to deal with the whole file, not individual parts of it. The process can be summarized in the following steps: Load appsettings.json and deserialize it into an object. Update properties on the object. Serialize the object into a JSON … Read more

How to use relative paths in a Windows Service

Relative paths are resolved relative to the current working directory. When you’re running a Windows Service, the default working directory is C:\Windows\system32 or C:\Windows\SysWOW64. Therefore relative paths are resolved from these system folders, which can lead to problems when read/writing files. Here are the most common problems you’ll run into: File or Directory cannot be … Read more