/// <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(); }
/// <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(); }
//收藏的函数实现 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(); } }
/// <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(); } }