Link to home
Start Free TrialLog in
Avatar of zimmer9
zimmer9Flag for United States of America

asked on

How to run an exe file in the same directory as the input file for a C# console application using VS2010?

How would you recode the attached C# Console application so that the executable can run in the same directory as the input file? Currently the exe runs fine as long as it is not in the same directory path as the input file. When I put the exe in the same directory as the input file, the Visual Studio Just-In-Time Debugger appears.
test.txt
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Hi zimmer9;

Instead of passing a path plus the filename just passed the filename without any path information something like the following.

string bankFilePath = "C.ard.out");

if (File.Exists(bankFilePath))
{
    File.Delete(bankFilePath);
}

Open in new window

If you need to you can get the path the currently running EXE using:

string startupPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
ASKER CERTIFIED SOLUTION
Avatar of Daniel Van Der Werken
Daniel Van Der Werken
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial