Provides instance of ProgramaticID that can be referenced by multiple different extensions.
示例#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 %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));
        }
示例#2
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 %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));
        }
示例#3
0
        /// <summary>
        /// Register file association
        /// </summary>
        /// <param name="exts">Extensions, for ex: *.png;*.jpg</param>
        /// <param name="appPath">Executable file</param>
        public static void RegisterAssociation(string appPath, string exts)
        {
            string[] ext_list = exts.Replace("*", "").Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (string ext in ext_list)
            {
                FileAssociationInfo fa = new FileAssociationInfo(ext);
                if (!fa.Exists)
                {
                    return;
                }

                ProgramAssociationInfo pa = new ProgramAssociationInfo(fa.ProgID);

                if (!pa.Exists)
                {
                    return;
                }

                ProgramVerb[] verbs = pa.Verbs;
                List<ProgramVerb> l = new List<ProgramVerb>();
                l.AddRange(verbs);

                //remove existed verb
                ProgramVerb openVerb = l.SingleOrDefault(v => v.Name == "open");
                if (openVerb != null)
                {
                    l.Remove(openVerb);
                }

                //add new value
                openVerb = new ProgramVerb("open", "\"" + appPath + "\" \"%1\"");
                l.Add(openVerb);

                //save & apply changes
                pa.Verbs = l.ToArray();

                GlobalSetting.SetConfig("ContextMenuExtensions", exts);
            }
        }