ahmed salah

ahmed salah

  • 1.6k
  • 530
  • 123.2k

if file exist open new form problem

Jan 25 2017 11:55 AM
I work in c# visual studio 2015 windows form 
 
I have two forms
 
CreateDatabase Form
 
Form1 form
 
I need when open my application to check IF Excel file exist or not
 
IF Excel file not exist go to form CreateDatabase Form if excel file not exist
 
And
 
IF   excel file database exist before open form1 
 
How to do that please
 
what i try as following :
 
in form1 load event i write following code
  1. CreateDatabase frm = new CreateDatabase();  
  2.            var fileName = string.Format("{0}\\Book3105.xlsx", Directory.GetCurrentDirectory());  
  3.            if (!File.Exists(fileName))  
  4.            {  
  5.   
  6.                Form1 frm1 = new Form1();  
  7.                frm.Show();  
  8.                frm1.Hide();  
  9.   
  10.   
  11.            }  
  12.            else  
  13.            {  
  14.   
  15.   
  16.                frm.Hide();  
  17.                this.Show();  
  18.            }  
 

Answers (4)