I have a ClickOnce application that needs to determine if an excel file exists or not, in order to decide whether to create it or write over it.
Excel.Workbook workBook;
if (File.Exists(fullFilePath)) {
workBook = excelApp.Workbooks.Open(fullFilePath);
} else {
workBook = excelApp.Workbooks.Add(ApplicationDeployment.CurrentDeployment.DataDirectory + @"\" + TEMPLATE_NAME);
workBook.SaveAs(path + "\\" + fileName, Excel.XlFileFormat.xlWorkbookNormal);
}
This works fine the first time the application is installed and used, but if I restart the application it no longer sees the file if it exists, causing the SaveAs to be executed and causing an exception. The exception is System.Runtime.InteropServices.COMException (0x800A03EC)
.