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);
有帮助吗?

解决方案

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

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top