How to open a file in the PC's default text editing software (not the default associated app)?

Viewed 716

Working in C#, I would like to start a process and open a file in the default text editing program, which is not necessarily the default program association for that filetype.

For example, say I wanted to open an html file. The default association for that file may be firefox. How could I open it in the default text editor (e.g. Notepad, Notepad++, etc.)?

Thanks for your help.

edit: The comment below said there is no way to set a default text editing program. Very well, is there a way to pretend that the file is a txt file?

1 Answers

Its in the registry:

    string edit = (string)Registry.GetValue(@"HKEY_CLASSES_ROOT\SystemFileAssociations\text\shell\edit\command", null, null);

    edit = edit.Replace("%1", @"c:\temp.txt");

    Process.Start("cmd.exe", "/c " + edit);

This will invoke the command it uses when you rightclick->Edit a text file instead of rightclick->Open

Related