0

I am using a .txt file to save data in a Windows Forms Application. The .txt is located at the same folder as the .exe. However, if I launch the app via shortcut (let's say a desktop shortcut), the app will save the .txt file in the desktop (even though the actual .exe is located somewhere else). The code I use is:

var myFile = File.Create(@"data.txt");
using (var sw = new StreamWriter(@"data.txt", true))
{
    sw.WriteLine("I like apples.");
}
user1924391
  • 255
  • 5
  • 13

1 Answers1

1

If you right click the shortcut and click the Properties link - You will see an option to change the Start In: path - this is where the programs CWD will be...

Milney
  • 6,253
  • 2
  • 19
  • 33
  • This works aswell. In my case, that field was blank. I changed it to the executable location and it works like a charm. Thanks – user1924391 Mar 06 '17 at 12:55