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?
Open Default Programs by clicking the Start button , and then clicking Default Programs. Use this option to choose which programs you want Windows to use, by default. If a program does not show up in the list, you can make the program a default by using Set Associations.
Windows Notepad is a simple text editor for Windows; it creates and edits plain text documents.
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
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