The best way is top set the association when you install it, but otherwise you have to play with the Registry:
[System.Runtime.InteropServices.DllImport("shell32.dll")]
static extern void SHChangeNotify(int wEventId, int uFlags, int dwItem1, int dwItem2);
private bool CreateFileAssociation(string extension, string className, string description, string exeProgram)
{
const int SHCNE_ASSOCCHANGED = 0x8000000;
const int SHCNF_IDLIST = 0;
if (extension.Substring(0, 1) != ".")
{
extension = "." + extension;
}
Microsoft.Win32.RegistryKey key1 = null;
Microsoft.Win32.RegistryKey key2 = null;
Microsoft.Win32.RegistryKey key3 = null;
try
{
key1 = Microsoft.Win32.Registry.ClassesRoot.CreateSubKey(extension);
key1.SetValue("", className);
key2 = Microsoft.Win32.Registry.ClassesRoot.CreateSubKey(className);
key2.SetValue("", description);
key3 = Microsoft.Win32.Registry.ClassesRoot.CreateSubKey(className + @"\Shell\Open\Command");
key3.SetValue("", exeProgram + @" ""%1""");
}
catch
{
return false;
}
finally
{
if (key2 != null)
{
key2.Close();
}
if (key3 != null)
{
key3.Close();
}
}
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0);
return true;
}