10

I'm trying to start an application programatically, but it always runs it in the folder of my application... For example:

If my app is located in C:\MyApp\myapp.exe and the other app is in C:\OtherApp\otherapp.exe, how can I start the other app in the folder in which it resides, rather than in the folder where my app resides?

Here is how I start the other app:

private void StartApp(OtherApp application)
{
    Process process = new Process();
    process.StartInfo.FileName = application.FileName;
    process.StartInfo.Arguments = application.AppName;
    process.Start();
}
Kiril
  • 39,672
  • 31
  • 167
  • 226
  • 2
    -1 couse scrolling through the intellisense method list instead of posting on SO would have benn faster and more productive (joking on the -1). – vaitrafra Jun 04 '10 at 10:00
  • @vaitrafra, I'm addicted to SO!!! – Kiril Jun 04 '10 at 10:03
  • @vaitrafra, remember that in SO just because the solution was obvious it doesn't mean that the question shouldn't be asked... anybody searching for this information on google will inevitably stumble on an SO answer. Nothing but good Karma from answering even the simplest question. – Kiril Jun 04 '10 at 15:15
  • @vaitrafra, I know :)... that's why my first comment was "I'm addicted to SO!!!" But you do have a point: it should have been obvious. – Kiril Jun 04 '10 at 17:55

3 Answers3

13

I guess you mean ProcessStartInfo.WorkingDirectory Property

Giorgi
  • 30,270
  • 13
  • 89
  • 125
  • that's what I needed... I was looking for a Directory property, but I should have been looking for a WorkingDirectory property! Thanks :). – Kiril Jun 04 '10 at 09:46
7

Use process.StartInfo.WorkingDirectory = pathToTheFolder;.

Femaref
  • 60,705
  • 7
  • 138
  • 176
6

Just set the WorkDirectory property.

process.StartInfo.WorkingDirectory = Path.GetDirectoryName(application.Filename);
djdd87
  • 67,346
  • 27
  • 156
  • 195