I'm opening a file using the OpenFile Dialog and I want to confirm that the file is in an excel format.
The file that I opened is "C:\Desktop\Distribution.xls", but both criteria of my if statement are evaluating to true. Is there another method that I should be using?
DialogResult result = openFileDialog1.ShowDialog();
if (result==DialogResult.OK)
{
file = openFileDialog1.FileName;
file = file.Trim();
if (!file.EndsWith(".xlsx")||!file.EndsWith(".xls"))
{
MessageBox.Show("Incorrect file format. Please save file in an .xls format");
}
else
{
book = application.Workbooks.Open(file);
sheet = (Worksheet)book.Worksheets[1];
range = sheet.get_Range("A1", "A1".ToString());
range.EntireRow.Delete(XlDirection.xlUp);
sheet.Cells[1, 2].EntireColumn.NumberFormat = "@";
book.SaveAs(csvConverstion, XlFileFormat.xlCSV);
book.Close(false, Type.Missing, Type.Missing);
application.Quit();
}