I have some trouble to understande why I´m getting an exception. I have something like this:
string path = "file.xls";
if (File.Exists(path))
{
Excel.Application xlApp = new Excel.Application();
Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(path); //exception
//...
}
Exception:
Unhandled Exception: System.Runtime.InteropServices.COMException: 'file.xls' could not be found
Well that´s why I´m checking with File.Exists
, so I dont get this exception. So how does this work, File.Exists
is true, but the file still cannot be found? If I´m using an absolute path, then it´s working. Why? I would like to use this without the absolute path, any ideas? Thank you
Edit: of course the file.xls
is in the same folder as my .exe
-> that´s why (as expected) File.Exists
is returning true. Just wanted to make this clear ;)