Question

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);
Était-ce utile?

La solution

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);

Autres conseils

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top