C#.NET读取一个文件目录下所有excel文件


 string defaultfilePath = "";

        private void btn_OpenFile_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog dialog = new FolderBrowserDialog();
            dialog.ShowNewFolderButton = false;
            dialog.Description = "请选择文件路径";
            if (defaultfilePath != "")
            {
                //设置此次默认目录为上一次选中目录  
                dialog.SelectedPath = defaultfilePath;
            }
            DialogResult result = dialog.ShowDialog();
            if (result == DialogResult.OK || result == DialogResult.Yes)
            {
                string foldPath = dialog.SelectedPath;
                txt_Directory.Text = defaultfilePath = foldPath;
                string[] files = Directory.GetFiles(txt_Directory.Text + @"\", "*.xls");
                foreach (string file in files)
                {
                    MessageBox.Show(file);
                }
            }
        }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM