Create two forms and use some codes like this:
Inside the main form:
public void SelectProgram(string ext)
{
IEnumerable<string> programList = RecommendedPrograms(ext);
if (programList.Count() > 0)
{
// open a new form to show the program in the list (to user select one of them)
frmSelectProgram frmSP = new frmSelectProgram(programList);
frmSP.ShowDialog();
}
else
{
// show an Open Dialog to the user to select a program
}
}
and use a method like below to find the file (the extension) associated to witch programs:
(this method is wrote by @LarsTech and i change some lines of them.)
using Microsoft.Win32;
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())
if(rk.GetValue(c.ToString())!=null)
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;
}
inside frmSelectProgram form:
public partial class frmSelectProgram : Form
{
private IEnumerable<string> _programList;
public frmSelectProgram(IEnumerable<string> programList)
{
InitializeComponent();
_programList = programList;
}
private void frmSelectProgram_Load(object sender, EventArgs e)
{
foreach (string pro in _programList)
{
// MessageBox.Show(pro);
// for example fill a list box
}
}
}