Esempio n. 1
0
        /// <summary>
        /// Create URL shortcut.
        /// </summary>
        /// <param name="p">Input parameters.</param>
        private static void LinkUrl(Params p)
        {
            IWshURLShortcut l = Sh.CreateShortcut(p.Output);

            l.TargetPath = p.TargetPath;
            l.Save();
        }
Esempio n. 2
0
        public static IWshURLShortcut getUrlShortcut(string path)
        {
            IWshURLShortcut shortcut = null;

            if (System.IO.File.Exists(path))
            {
                var wsh = new IWshShell_Class();
                shortcut = wsh.CreateShortcut(path);
            }
            return(shortcut);
        }
Esempio n. 3
0
        /// <summary>
        /// 工具栏的"添加到收藏夹"菜单,将网页收藏
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MenuFavorites_Click(object sender, EventArgs e)
        {
            string            name     = WebBrowserList[TabControl.SelectedIndex].DocumentTitle.ToString();
            string            url      = this.WebBrowserList[TabControl.SelectedIndex].Url.ToString();
            ToolStripMenuItem menuItem = new ToolStripMenuItem();

            menuItem.Text        = name;
            menuItem.ToolTipText = url;
            menuItem.Click      += new System.EventHandler(this.Favourites_Click);
            this.ToolFavorites.DropDownItems.Add(menuItem);
            IWshShell_Class shell    = new IWshShell_ClassClass();
            IWshURLShortcut shortcut = shell.CreateShortcut("Favourites\\" + name + ".url") as IWshURLShortcut;

            shortcut.TargetPath = url;
            shortcut.Save();
        }
Esempio n. 4
0
        public static IEnumerable <InternetShortcut> Decode(IDataObject data)
        {
            WshShell shell = new WshShell();

            foreach (FileGroupDescriptor.File i in FileGroupDescriptor.Decode(data))
            {
                if (i.Name.EndsWith(".url", StringComparison.OrdinalIgnoreCase))
                {
                    string          path  = i.Write(System.Environment.GetEnvironmentVariable("TEMP"));
                    IWshURLShortcut wshSc = (IWshURLShortcut)shell.CreateShortcut(path);
                    System.IO.File.Delete(path);
                    InternetShortcut sc = new InternetShortcut();
                    sc.Name = i.Name;
                    sc.Url  = wshSc.TargetPath;
                    yield return(sc);
                }
            }
        }
Esempio n. 5
0
        //收藏的函数实现
        private void addFavorites(string url, string filename, string savepath)
        {
            string path = Environment.GetFolderPath(Environment.SpecialFolder.Favorites);

            if (!System.IO.File.Exists(path + "\\" + filename + savepath + ".url"))
            {
                IWshShell_Class shell    = new IWshShell_ClassClass();
                IWshURLShortcut shortcut = null;
                if (savepath == "Favorites")
                {
                    shortcut = shell.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.Favorites) + "\\" + filename + ".url") as IWshURLShortcut;
                    toolStripStatusLabel1.Text = "...当前页面收藏完成";
                }
                else
                {
                    shortcut = shell.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.Favorites) + "\\" + savepath + "\\" + filename + ".url") as IWshURLShortcut;
                }
                shortcut.TargetPath = url;
                shortcut.Save();
            }
        }
Esempio n. 6
0
        /// <summary>
        /// 初始化收藏夹
        /// </summary>
        private void InitFavourites()
        {
            DirectoryInfo directory = new DirectoryInfo("Favourites");

            if (!directory.Exists)
            {
                Directory.CreateDirectory("Favourites");
            }
            foreach (FileInfo file in directory.GetFiles())
            {
                try
                {
                    IWshShell_Class   shell    = new IWshShell_ClassClass();
                    IWshURLShortcut   shortcut = shell.CreateShortcut(file.FullName) as IWshURLShortcut;
                    ToolStripMenuItem menuItem = new ToolStripMenuItem();
                    menuItem.Text        = file.Name;
                    menuItem.ToolTipText = shortcut.TargetPath.ToString();
                    menuItem.Click      += new System.EventHandler(this.Favourites_Click);
                    this.ToolFavorites.DropDownItems.Add(menuItem);
                }
                catch { }
            }
        }
Esempio n. 7
0
        /// <summary>
        /// 首先要添加应用,选择COM组件中的“Windows Script Host Object Model”
        /// </summary>
        /// <param name="url"></param>
        /// <param name="filename"></param>
        /// <param name="savepath"></param>
        private void addFavorites(string url, string filename, string savepath)
        {
            string path = Environment.GetFolderPath(Environment.SpecialFolder.Favorites);

            if (!System.IO.File.Exists(path + "\\" + filename + savepath + ".url"))
            {
                IWshShell_Class shell    = new IWshShell_ClassClass();
                IWshURLShortcut shortcut = null;
                if (savepath == "Favorites")
                {
                    shortcut = shell.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.Favorites) + "\\" + filename + ".url") as IWshURLShortcut;
                    if (MessageBox.Show("网址已经添加到收藏夹", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information) == DialogResult.OK)
                    {
                        this.Close();
                    }
                }
                else
                {
                    shortcut = shell.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.Favorites) + "\\" + savepath + "\\" + filename + ".url") as IWshURLShortcut;
                }
                shortcut.TargetPath = url;
                shortcut.Save();
            }
        }