CJLeit Posted June 28, 2006 Posted June 28, 2006 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! Quote
Leaders snarfblam Posted June 28, 2006 Leaders Posted June 28, 2006 I would use conditional compiling. Have one filename for the debug build and another for the release build. #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 Quote [sIGPIC]e[/sIGPIC]
mskeel Posted June 29, 2006 Posted June 29, 2006 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? Quote
CJLeit Posted July 5, 2006 Author Posted July 5, 2006 The #IF DEBUG worked perfect for what I needed. Thank you very much! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.