winform C#实现查看收藏夹功能

来源:互联网 发布:网络歌曲 什么什水自流 编辑:程序博客网 时间:2024/05/29 17:47
//zjut
//安静是明白
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.IO;using System.Collections;namespace JBrowser{    public partial class Form4 : Form    {        public ArrayList alTitle = new ArrayList();        public ArrayList alUrl = new ArrayList();        // 声明URL文件的读操作函数 GetPrivateProfileString()        [System.Runtime.InteropServices.DllImport("kernel32")]        private static extern int GetPrivateProfileString(string section, string key, string def, System.Text.StringBuilder retVal, int size, string filePath);        private string sPath = null;        public Form4()        {            InitializeComponent();        }        private void Form4_Load(object sender, EventArgs e)        {            //获取“收藏夹”文件路径            string myFavoritesPath = System.Environment.GetFolderPath(Environment.SpecialFolder.Favorites);            TreeNode root = new TreeNode();            root.Text = @"收藏夹";            root.Tag = myFavoritesPath;            treeView1.Nodes.Add(root);            BindChild(root);        }        private void BindChild(TreeNode fNode)        {            string path = fNode.Tag.ToString();            //父目录            DirectoryInfo fDir = new DirectoryInfo(path);            FileSystemInfo[] finfos = fDir.GetFileSystemInfos();            foreach (FileSystemInfo f in finfos)            {                string type = f.GetType().ToString();                TreeNode node = new TreeNode();                node.Text = f.Name;                node.Tag = f.FullName;                fNode.Nodes.Add(node);                if ("System.IO.DirectoryInfo" == type) //是文件夹时才递归调用自己                {                    BindChild(node);                }            }        }        private void treeView1_DoubleClick(object sender, EventArgs e)        {            string str1 = ReadValue("InternetShortcut", "URL");            MessageBox.Show(str1);        }        public string ReadValue(string section, string key)        {            string sPath = Convert.ToString(treeView1.SelectedNode.Tag);            // 每次从ini中读取多少字节            System.Text.StringBuilder temp = new System.Text.StringBuilder(255);            // section=配置节,key=键名,temp=上面,path=路径            GetPrivateProfileString(section, key, "", temp, 255, sPath);            return temp.ToString();        }    }}


 一个下午不断上网查资料,终于实现了将Favorites文件夹下的url文件读取进来,并且得到文件的url地址,接下来的navigate就简单了