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);
                }
            }
        }

 

posted @ 2017-07-29 09:27  宋佳莉  阅读(5461)  评论(0编辑  收藏  举报