How to get recommended programs associated with file extension in C#
Solution 1:
I wrote a small routine:
public IEnumerable<string> RecommendedPrograms(string ext)
{
List<string> progs = new List<string>();
string baseKey = @"Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\." + ext;
using (RegistryKey rk = Registry.CurrentUser.OpenSubKey(baseKey + @"\OpenWithList"))
{
if (rk != null)
{
string mruList = (string)rk.GetValue("MRUList");
if (mruList != null)
{
foreach (char c in mruList.ToString())
progs.Add(rk.GetValue(c.ToString()).ToString());
}
}
}
using (RegistryKey rk = Registry.CurrentUser.OpenSubKey(baseKey + @"\OpenWithProgids"))
{
if (rk != null)
{
foreach (string item in rk.GetValueNames())
progs.Add(item);
}
//TO DO: Convert ProgID to ProgramName, etc.
}
return progs;
}
which gets called like so:
foreach (string prog in RecommendedPrograms("vb"))
{
MessageBox.Show(prog);
}
Solution 2:
Ever wanted to programmatically associate a file type on the system with your application, but didn't like the idea of digging through the registry yourself? If so, then this article and code are right for you.
System File Association