I have a text file named "Config.txt". when my application starts it will be read as contained in the file and load settings. I use Registry for my application startup with windows. code below:
RegistryKey rk = Registry.CurrentUser.OpenSubKey
("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (checkStartup.Checked)
rk.SetValue("MyApplication", Application.ExecutablePath);
else
rk.DeleteValue("MyApplication", false);
Code is running. But when my application runs it doesn't read the config. results in all settings being null.If I click manual application run normal :D . Please advise on other solutions.
This is because of working directory. When application launch by windows on start up it has different working directory than when you double click on it.
you can use this to change working directory programmatically.
using System.IO;
// ...
Environment.CurrentDirectory = Path.GetDirectoryName(Application.ExecutablePath);
// read settings from config