# Using 'dynamic' to save lines

I am pushing an Excel file to the server and then reading it's contents. XLS and XLSX files need to be read differently, but the DLL that I'm using has the EXACT same function calls for both types. If I use a 'dynamic' type, I can save a lot of lines of code and avoid redundancy. However, I've been told many times before to avoid using dynamic if possible. Is this a good place to use it?

dynamic excelFile; // is this a good use of dynamic?
switch (fileExtension)
{
case "xls":
excelFile = new Excel2007();
break;
case "xlsx":
excelFile = new Excel();
break;
default:
results.Message = string.Format("{0} is of an unrecognized format.", uploadFile.FileName);
return RedirectToAction("ImportWizard");
}

excelFile.OpenDatabase(targetPath, new FieldData());
excelFile.CurrentTable = excelFile.Tables[0];

excelFile.CloseDatabase();

• Don't they have a common interface or base class? – ChrisWue Oct 23 '13 at 1:26
• Not at this stage (wasn't sure if that was really needed), but if dynamic isn't a good choice here than I can implement that. – Sabe Oct 23 '13 at 15:38