1

I want to run or access files from the bin folder in a Visual Studio project. I've created a simple windows forms application and added one button, so what should I code to run file from the bin folder. I tried System.Diagnostics.Process.Start("filename.extension") but nothing happened.

  • Try `System.Diagnostics.Process.Start("~/bin/filename.extension")`, check if that helps. Note: it'll launch only executables. – Am_I_Helpful May 30 '17 at 17:09
  • the "bin" folder only exists in a VS project folder structure, in real world deployment you can't assume such a folder exists. So what is the relative path (relative to the exe) to the file you want to access? – kennyzx May 31 '17 at 07:30
  • You should add the file from Visual Studio by `Add Existing Item`. And then right click and in the properties select `Compile:None` and `Copy to Output Directory:Always`. Now your files should be copied to the same folder as *.exe. You should be able to use `Process.Start` – mcy May 31 '17 at 08:04
  • ok. i created a seperated folder named Data with "Add Existing Item" and i want to run .exe file from that folder i try System.diagonastic.process.start("Data/file.exe"); >it doesnt work But when i place file in root to the project it works please tell me the solution so i could code to run file from Data folder or other folder – Sukhwinder Saini May 31 '17 at 09:06
  • The reason is that paths in `process` are relative i.e. they are relative to the .exe file. If you want to use a folder, than you can take a look at https://stackoverflow.com/questions/1658518/getting-the-absolute-path-of-the-executable-using-c for getting directory, and then combine it with *Data/file.exe* using `Path.Combine`. After these you can use the resultant path string. – mcy May 31 '17 at 13:13

0 Answers0