打开文件对话框

            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Multiselect = false;
            dialog.Title = "请选择需要导入的Excel文件";
            dialog.Filter = "文件|*.xls;*.xlsx;*.csv";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                this.textBox1.Text = dialog.FileName;
            }
                if (string.IsNullOrEmpty(this.textBox1.Text))
                {
                    MessageBox.Show("请选择一个有效文件");
                    return;
                }
                if (!File.Exists(this.textBox1.Text))
                {
                    MessageBox.Show("您选择的文件不存在");
                    return;
                }
                var filename = this.textBox1.Text;

posted @ 2022-05-30 17:14  highlightyys  阅读(11)  评论(0编辑  收藏  举报