/// <summary> /// Creates actual extension association key in registry for the specified extension and supplied attributes. /// </summary> /// <param name="progId">Name of expected handling program.</param> /// <param name="perceivedType"><see cref="PerceivedTypes"/>PerceivedType of file type.</param> /// <param name="contentType">MIME type of file type.</param> /// <param name="openwithList"></param> /// <returns>FileAssociationInfo instance referring to specified extension.</returns> public FileAssociationInfo Create(string progId, PerceivedTypes perceivedType, string contentType, string[] openwithList) { FileAssociationInfo fai = new FileAssociationInfo(extension); if (fai.Exists) { fai.Delete(); } fai.Create(); fai.ProgID = progId; if (perceivedType != PerceivedTypes.None) { fai.PerceivedType = perceivedType; } if (contentType != string.Empty) { fai.ContentType = contentType; } if (openwithList != null) { fai.OpenWithList = openwithList; } return(fai); }
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 an already existing program id with a list of extensions. /// </summary> /// <param name="progId">The program id to associate extensions with.</param> /// <param name="extensions">String array of extensions to associate with program id.</param> public void Associate(string progId, params string[] extensions) { foreach (string s in extensions) { FileAssociationInfo fai = new FileAssociationInfo(s); if (!fai.Exists) { fai.Create(progId); } fai.ProgID = progId; } }
/// <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)); }