title: unable to open excel file from c# application
body: <p>I am trying to open an excel file through <code>open file dialog</code> but I am getting the following error </p>
  
  <p><img src="https://i.stack.imgur.com/6aTSs.png" alt="enter image description here"> </p>
  
  <p>this the code i'v written, lemme know where it goes wrong </p>
  
  <pre><code>Excel.Application excelApp = new Excel.Application();
  Excel.Workbook newWorkbook = excelApp.Workbooks.Add();  
  Excel.Workbook excelWorkbook = null;
  OpenFileDialog ofd = new OpenFileDialog();
  ofd.Filter = "Excel Files |*.xlsx";
  ofd.InitialDirectory = @"C:\";
  if (ofd.ShowDialog() == DialogResult.OK)
  {
      string path = System.IO.Path.GetFullPath(ofd.FileName);
      try
      {
          excelWorkbook = excelApp.Workbooks.Open(path,
          0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "",
          true, false, 0, true, false, false);
      }
      catch (Exception theException)
      {
          String errorMessage;
          errorMessage = "Error: ";
          errorMessage = String.Concat(errorMessage, theException.Message);
          errorMessage = String.Concat(errorMessage, " Line: ");
          errorMessage = String.Concat(errorMessage, theException.Source);
          MessageBox.Show(errorMessage, "Error");
      }
  }
  </code></pre>
  
  <p>I am doing this coz I need to get values from the excel sheet. Please let me know if you require more details.</p>
  
  <p>Edit -: when I looked closely I understood that the message box is not prompted for the first trial of opening the file, but the file does not open and then the message box appears during every successive trial of opening it.
  As suggested by @Pankaj, I tried adding Finally at the bottom but I still get the message box after 2nd trial of opening the file.</p>