예제 #1
0
        /// <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"
        /// extensions = ".txt", ".text"</example>
        static public void Associate(string progId, string executablePath, string description, params string[] extensions)
        {
            foreach (string s in extensions)
            {
                FileAssociationInfo fai = new FileAssociationInfo(s);

                if (!fai.Exists)
                {
                    fai.Create(progId);
                }

                fai.ProgID = progId;
                string exeName = executablePath.Substring(executablePath.LastIndexOf('\\') + 1);
                fai.OpenWithList    = new string[] { exeName };
                fai.OpenWithProgids = new string[] { progId };
                OpenWithListProcess(s, progId, exeName);
            }

            ProgramAssociationInfo pai = new ProgramAssociationInfo(progId);

            pai.Create(description, EditFlags.OpenIsSafe | EditFlags.AlwaysShowExtension,
                       new ProgramVerb("open", "\"" + executablePath + "\"" + " \"%1\""));
            // pai.InfoTip="prop:FileDescription;Company;FileVersion;Create;Size";
            //pai.TileInfo = "prop:FileDescription;Company;FileVersion;Create;Size";
            pai.AlwaysShowExtension = true;
            pai.DefaultIcon         = new ProgramIcon(executablePath, 0);
        }
예제 #2
0
        /// <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);
        }
예제 #3
0
        /// <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;
            }
        }