FileAssociation/AssociationManager.cs
/// <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>
Associates a single executable with a list of extensions.
Associates a single executable with a list of extensions .
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));
      }
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 ( " " , executablePath ) ) ; }
Associates a single executable with a list of extensions.
Associates a single executable with a list of extensions .
progId
string
Name of program id
Name of program id
executablePath
string
Path to executable to start including arguments.
Path to executable to start including arguments .
extensions
String array of extensions to associate with program id.
String array of extensions to associate with program id .
example
progId = "MyTextFile"
executablePath = "notepad.exe %1"
extensions = ".txt", ".text"
progId = " MyTextFile " executablePath = " notepad . exe %1 " extensions = " . txt " " . text "