I'm going to assume, for the sake of this answer, that you haven't built an installer for your application. If you had, you could register the extension using the installer. Anyway, assuming that you haven't built an installer, you are going to need to modify the registry to perform the association. Be aware that this means that your application will have to run as administrator to actually make the modification. Something like this should help:
public static void RegisterFileExtension(string extension, string applicationPath)
{
if (!extension.StartsWith("."))
{
extension = "." + extension;
}
string applicationName = Path.GetFileNameWithoutExtension(applicationPath);
string keyName = applicationName + "_file";
SetSubKey(@"Software\Classes\" + extension, "", keyName);
SetSubKey(@"Software\Classes\" + extension + @"\shell\open\command", "", "\"" + applicationPath + "\" \"%1\"");
}
private static void SetSubKey(string registryPath, string registryKey, value)
{
using RegistryKey key = Registry.CurrentUser.CreateSubKey(registryPath);
key.SetValue(registryKey, value);
}
Obviously, the
applicationPath
is the path to your executable.