2

I have a c# form application. It opens a text file upon loading. From this text file it reads the default settings. It then fills the numericupdown fields and textbox fields with the default data.

I want to run this every night at a specific time. The windows task seems to be trying to open the program. However, upon loading it gets a FileNotFoundException Could not find file 'C:\Windows\system32\Settings.txt Which is nowhere close to my application run folder. It opens properly when running from command line and using run in MVS2013.

in my program I am searching for this file using relative pathing

could anyone shed some light on this ridiculousness? I would greatly appreciate it.

ForgottenOne
  • 85
  • 1
  • 4
  • 16

1 Answers1

7

Your path is relative to the working directory, which seems to be "C:\Windows\system32" if you didn't specify any. So possible solutions are, set working directory to the directory of your executable file (the "Start in (optional)" field) :

enter image description here

.. or modify your program to use absolute path of the executable (you can get the absolute path programmatically).

Community
  • 1
  • 1
har07
  • 88,338
  • 12
  • 84
  • 137
  • I am planning to deploy this to customers at some point. They will all use different directories so absolute pathing is a little out of the question. However I plan to have a tutorial for them to automate the program. I will simply instruct them to fill in the working directory. Thank you! – ForgottenOne Aug 19 '14 at 05:33
  • Absolute path of the executable determined at run-time according to current location of the exe file. To be clear, the path will change if the executable moved to different directory. So I can't see why it is not an option... Anyway, you're welcome – har07 Aug 19 '14 at 05:37