zoukankan      html  css  js  c++  java
  • c# 获取收藏夹目录到树型控件

    private void ReportForm_Load(object sender, EventArgs e)
    {
                DirectoryInfo favfolder = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.Favorites));
                FileSystemInfo[] myFileSystemInfo = favfolder.GetFileSystemInfos();
                TreeNode RootNode = new TreeNode();
                RootNode.Text = "收藏夹";
                this.treeView1.Nodes.Add(RootNode);
                this.treeView1.ExpandAll();
                GetDir(myFileSystemInfo, RootNode);

    }
            private void GetDir(FileSystemInfo[] myFavDir, TreeNode RootNode)
            {
                string myStr = "";
                string myUrl = "";
                string myDesc = "";
                if (myFavDir == null)
                {
                    throw new ArgumentNullException("myfavdir");
                }
                foreach (FileSystemInfo filesysteminfo in myFavDir)
                {
                    TreeNode tn = new TreeNode();
                    //文件目录
                    if (filesysteminfo.GetType() == typeof(DirectoryInfo))
                    {
                        tn.Text = filesysteminfo.Name;
                        RootNode.Nodes.Add(tn);
                        //强制转化为文件目录格式
                        DirectoryInfo childfile = (DirectoryInfo)filesysteminfo;
                        //递归调用
                        GetDir(childfile.GetFileSystemInfos(), tn);
                    }
                    //文件格式
                    else if (filesysteminfo.GetType() == typeof(FileInfo))
                    {
                        string fitler = ".url";
                        //过滤功能
                        if (filesysteminfo.FullName.ToLower().EndsWith(fitler.ToLower()))
                        {
                            using (StreamReader sr = new StreamReader(filesysteminfo.FullName, Encoding.Default))
                            {
                                myStr = sr.ReadLine();
                                while (myStr != null)
                                {
                                    //获取URL地址
                                    if (myStr.ToLower().StartsWith(URLPrefix))
                                    {
                                        myUrl = myStr.Substring(URLPrefix.Length);

                                    }
                                    else if (myStr.ToLower().StartsWith(DescriptionPrefix))
                                    {
                                        myDesc = myStr.Substring(DescriptionPrefix.Length);
                                    }
                                    myStr = sr.ReadLine();
                                }
                            }
                            TreeNode tnchild = new TreeNode();
                            tnchild.Text = filesysteminfo.Name;
                            tnchild.Tag = myUrl;
                            RootNode.Nodes.Add(tnchild);
                        }
                    }
                }

            }

  • 相关阅读:
    Tomcat9报错 The valid characters are defined in RFC 7230 and RFC 3986
    Job for ssh.service failed because the control process exited with error code.......
    解决 ora-28001 密码过期的处理办法
    Vmware unknow Interface ens33
    ubuntu桌面环境安装中文环境
    (CRON) info (No MTA installed, discarding output)” error in the syslog
    SSH Secure Shell链接Ubuntu报错Server responded "Algorithm negotiation failed"
    mysql备份数据库出错mysqldump: [ERROR] unknown option '--no-beep'
    dclcommon200.bpl
    字节 汉字判断
  • 原文地址:https://www.cnblogs.com/chenqingwei/p/1769647.html
Copyright © 2011-2022 走看看