In my application I want to open a text file, which has no .txt extension. Is there any way to get the standard application for .txt files in .NET (C#)? Sure I could use “notepad”, but there might be some people (like me), who prefer another (their standard) editor.
Edit:
The registry key “[HKEY_CLASSES_ROOT]\txtfile\shell\open\command” references notepad, but that’s not my standard app for txt files. How do I get the my current standard app for .txt?
The absolute best option is to use
ShellExecuteEx, passing theSEE_MASK_CLASSNAMEflag, to open this file as if it were a".txt". This is the only method that will support things like DDE-based and drag-and-drop-based file opening mechanisms.But if you want to do it yourself (e.g. running with partial trust and can’t p/invoke
ShellExecuteEx), here’s how:There’s another level of indirection. You first have to lookup
Read the default value out of that key, call it txtkey.
Then check
There’s also a function to do this for you: AssocQueryString