Tell if running program from VS

CJLeit

Freshman
Joined
Feb 1, 2006
Messages
32
Hello,

Is there a way in your code to tell if the code is running from within Visual Studio or if it's running from a compiled .exe? I have a text file that I want to open from a different location depending on if I'm working on the app in VS or if it's a exe running on a user's machine.

Thanks!
 
I would use conditional compiling. Have one filename for the debug build and another for the release build.
C#:
#if DEBUG
    const string filePath = @"C:\Document And Settings\Thor\My Documents\Test.txt";
#else
    const string filePath = IO.Path.Combine(Application.StartupPath, "things.txt");
#endif
 
You could always just have the text file open from the same location as the exe is running. When you're running out of visual studio the file would be located in your bin directory, once deployed, it would probably be in "C:\Program Files\Name Of App".

Does the path to the file have to be hard coded in? If you need the flexibility, why not pass the file path in as an argument to your program?
 
Back
Top