public void AssociateExtension() { try { FileAssociationInfo fai = new FileAssociationInfo(ReplayExt); if (!fai.Exists) { fai.Create("GhostbladeReplays"); //Specify MIME type (optional) fai.ContentType = "application/ghostblade-replay"; //Programs automatically displayed in open with list fai.OpenWithList = new string[] { "Ghostblade.exe" }; } ProgramAssociationInfo pai = new ProgramAssociationInfo(fai.ProgID); if (!pai.Exists) { pai.Create ( //Description of program/file type "Ghostblade Replay", new ProgramVerb ( //Verb name "Open", //Path and arguments to use AppDomain.CurrentDomain.BaseDirectory + "Ghostblade.exe %1" ) ); //optional pai.DefaultIcon = new ProgramIcon(AppDomain.CurrentDomain.BaseDirectory + "LGR.ico"); } else if (pai.Verbs[0].Command != (AppDomain.CurrentDomain.BaseDirectory + "Ghostblade.exe %1")) { pai.Verbs[0] = new ProgramVerb ( //Verb name "Open", //Path and arguments to use AppDomain.CurrentDomain.BaseDirectory + "Ghostblade.exe %1" ); pai.DefaultIcon = new ProgramIcon(AppDomain.CurrentDomain.BaseDirectory + "LGR.ico"); } } catch { } }
/// <summary> /// Associates a single executable with a list of extensions. /// </summary> /// <param name="progId">Name of program id</param> /// <param name="executablePath">Path to executable to start including arguments.</param> /// <param name="extensions">String array of extensions to associate with program id.</param> /// <example>progId = "MyTextFile" /// executablePath = "notepad.exe %1" /// extensions = ".txt", ".text"</example> public void Associate(string progId, string executablePath, params string[] extensions) { foreach (string s in extensions) { FileAssociationInfo fai = new FileAssociationInfo(s); if (!fai.Exists) { fai.Create(progId); } fai.ProgID = progId; } ProgramAssociationInfo pai = new ProgramAssociationInfo(progId); if (!pai.Exists) { pai.Create(); } pai.AddVerb(new ProgramVerb("open", executablePath)); }