views:

28

answers:

1

So I got a nice piece of code that allows me to enable autostart of program by clicking one button and disable by clicking other (it uses "SetValue" to create register entry and "DeleteValue" to discard it). I used it in simple program, and it did started with Windows as I wanted. The problem started when I used the same code in more sophisticated program, which saves its settings in files in "debug" folder (which is default location for textreader and textwriter) During startup, it showed exception and when I clicked to continue, it opened with default settings. The funny thing is that it said "System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Documents and Settings\OWner\autostart.txt'." even though autostart.txt was never supposed to be in this folder. I guess that when autostarting, the program starts looking for configuration files in C:\Documents and Settings\OWner\ instead of its own folder. Anyone has any idea why?

A: 

You have 2 (or more) options:

  1. Discover the path of where your application executes (various ways to do this).
  2. Set the working directory in your shortcut/launcher.
leppie
As for 1., I used Assembly.GetExecutingAssembly().Location and it turned out that it executes in debug folder as always
Gatlimir
So build up your path to autostart.txt with this value, or not? You could use Path.Combine(String, String)
Andreas