Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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!

  • Leaders
Posted

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

[sIGPIC]e[/sIGPIC]
Posted

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?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...