Reputation: 111
Iam making a program that's a suppose run from a USB key. But i have problem running file that are in a folder.
Usb folder/file structure looks like:
I can execute the install.exe file but running this code
private void Icon_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("install.exe");
}
But how do i make it to start the file in the sub folder?
Upvotes: 1
Views: 256
Reputation: 29233
You can temporarily navigate to the directory, run the executable, then go back to where you were:
var dir = Environment.CurrentDirectory;
Environment.CurrentDirectory = Path.Combine(dir, "data", "install");
System.Diagnostics.Process.Start("install2.exe");
Environment.CurrentDirectory = dir;
Upvotes: 2
Reputation: 4025
My initial answer mistook your problem with wanting to autorun the file upon inserting the USB drive.
My understanding is that your question is how to use the code you provided to run a file in a sub folder. And here are a few options:
Use a relative path ".\data install\install2.exe" and this will work if your program is started/executing from its own path.
Read the current excutable path and use it to construct a new path to that sub folder (check this question for an example)
Upvotes: 0