-2

I want to open the document with wordpad.exe but it is still opening with microsoft word

I currently have:

string fullPath = helpFiles[index];
ProcessStartInfo psi = new ProcessStartInfo("wordpad.exe");
psi.FileName = Path.GetFileName(fullPath);
psi.WorkingDirectory = Path.GetDirectoryName(fullPath);
psi.Arguments = fullPath;
Process.Start(psi);
keyboardP
  • 68,824
  • 13
  • 156
  • 205
Chris
  • 681
  • 1
  • 6
  • 16

2 Answers2

1

I asume fullPath is your document's name. You're setting the FileName property to the document which means it'll open in the default document editor (Word in this case).

The overload of ProcessStartInfo you're using sets the filename for you but you're replacing that value with Path.GetFileName(fullPath); which is why wordpad.exe is completely ignored. Set the FileName as wordpad and the arguments as your file path (i.e remove your FilePath line).

ProcessStartInfo psi = new ProcessStartInfo("wordpad");
psi.WorkingDirectory = Path.GetDirectoryName(fullPath);
psi.Arguments = fullPath;
Process.Start(psi);
keyboardP
  • 68,824
  • 13
  • 156
  • 205
  • that makes more sense, I assumed fileName is the name of the file I want to open, not the process. – Chris Aug 08 '13 at 21:53
0

You should just be doing this:

string fullPath = helpFiles[index];
//Check to make sure the path is valid
Process.Start(fullPath);

And let the computer determine the best program to open the file with, according to how the user has their file defaults set up.

Joe Brunscheon
  • 1,949
  • 20
  • 21
  • Not necessarily, what if OP's program has an option asking if the user wants to open in `wordpad`? – keyboardP Aug 08 '13 at 18:57
  • Agreed, if OP wants the application to open specifically in wordpad, something different should be done. I was pointing out that the OS already does file type associations and will use them to open the appropriate application, according to how the user has their associations specified on the machine. It's the functionality I would expect as a user. – Joe Brunscheon Aug 08 '13 at 19:03
  • I agree, if this isn't going to be expected by the user then it would be bad UX IMHO. I was just saying that there are legitimate reasons you would want to avoid the default program as a dev. – keyboardP Aug 08 '13 at 19:06