Beispiel #1
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();
        }
Beispiel #2
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();
            }
        }
Beispiel #3
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 { }
            }
        }
Beispiel #4
0
        /// <summary>
        /// 添加收藏
        /// </summary>
        /// <param name="favorite"></param>
        /// <param name="savePath"></param>
        /// <returns></returns>
        public bool AddFavorite(WFavorite favorite, string savePath)
        {
            try
            {
                var path      = Environment.GetFolderPath(Environment.SpecialFolder.Favorites) + "\\" + favorite.Title + ".url";
                var fileExist = File.Exists(path);
                if (!fileExist)
                {
                    IWshShell_Class shell = new IWshShell_ClassClass();
                    IWshURLShortcut shortcut;
                    if (savePath == "Favorites")
                    {
                        var pathLink = Environment.GetFolderPath(Environment.SpecialFolder.Favorites) + "\\" + favorite.Title + ".url";
                        shortcut = shell.CreateShortcut(pathLink) as IWshURLShortcut;
                    }
                    else
                    {
                        var pathLink = Environment.GetFolderPath(Environment.SpecialFolder.Favorites) + "\\" + savePath + "\\" + favorite.Title + ".url";
                        shortcut = shell.CreateShortcut(pathLink) as IWshURLShortcut;
                    }

                    if (shortcut != null)
                    {
                        shortcut.TargetPath = favorite.Url;
                        shortcut.Save();
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                FileLog.LogError(ex);
            }

            return(false);
        }
        /// <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();
            }
        }
Beispiel #6
0
 /// 得到路径
 /// <summary>
 /// 得到路径
 /// </summary>
 /// <param name="path"></param>
 /// <returns></returns>
 private string GetPath(string path)
 {
     if (path.IndexOf(".lnk") > 0 || path.IndexOf(".LNK") > 0)
     {
         IWshShell_Class shell = new IWshShell_ClassClass();
         IWshShortcut _shortcut = shell.CreateShortcut(path) as IWshShortcut;
         if(0 >_shortcut.TargetPath .IndexOf ("{") )
         return _shortcut.TargetPath;
     }
     return path;
 }