Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

Exception handling for OpenFileDialog and selecting files?

$
0
0

Hi all,

Im using an OpenFileDialog to find a file and open it in my windows form application. I trying to specify the file i want to select which is an excel file " Partitions.xlsx"  and return an error if this file (or any other file) i have selected is not equal to the excel file i want it to be ( ="Partitions.xlsx"). As i do not want the wrong file to be loaded!!

any help please?!

iv included my code that im using at the moment below:

 DataTable dt;
        OleDbConnection conn;
        OleDbDataAdapter mydataAdapter;

        private void button1_Click(object sender, EventArgs e)
        {
       
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                this.textBox1.Text = openFileDialog1.FileName;
            }                 
       
        }

Thanks!!

regards Ky


Viewing all articles
Browse latest Browse all 12583

Trending Articles