How do you open a file for editing from C# code, i.e. equivalent to the user right-clicking on it and selecting 'Edit' instead of 'Open'? I've got Process.Start(<filename>)
for the equivalent of 'Open', but I specifically need the 'Edit' option in this case.
If there isn't an easier way of doing it, I'm assuming I probably need to inspect the registry for the 'Edit' action associated with the file type and invoke that action somehow, but I'm not sure where to look or how to do so reliably.
Anyone know the best way of doing this?
Not all extensions have the Edit ProcessStartInfo.Verb, but the following may help you in some cases.
var runFile = new ProcessStartInfo(pathToFile) {Verb = "edit"};
Process.Start(runFile);
If you want to check to see if the Edit verb is valid before starting the related process, you could try the following:
public bool HasEdit()
{
var startInfo = new ProcessStartInfo(pathToFile);
return startInfo.Verbs.Any(verb => verb == "edit");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With