0

I'm building a C# addin for Autodesk Inventor. The only reason this is relevant is because I had to uncheck the box "Register for COM Interop".

Here's what I'm using. The xls is always in the same directory the code is running in. I've tried this with an absolute path as well, but I get the same error. The bool is for testing only, but it returns true. The file is not read-only.

bool fileExists = File.Exists ("Assembly3.xls");
xlBook = xlApp.Workbooks.Open ("Assembly3.xls");

Error message I'm getting: https://dl.dropbox.com/u/46698764/cantFindFile.png Since it says COMException, I'm thinking my problem might be because I unchecked the "Register for COM Interop" box. If this is the case, can someone recommend a different way to open the workbook?

If it matters, I have Excel 2010.

Brandon
  • 1,058
  • 1
  • 18
  • 42

1 Answers1

1

Try specifying the full path. Excel might be opening with a different startup directory and it could be looking in that directory for the XLS file. Since you are hosted as an addin, you might need to play with different ways to get the path. A few places to start would be:

Application.StartupPath

GetCurrentDirectory

John Koerner
  • 37,428
  • 8
  • 84
  • 134
  • Right, but I mentioned that I tried that. I get the same error. The full path did not help. – Brandon Jun 15 '12 at 17:46
  • What directory is this running in? Could it be a permission issue with Windows Vista/7? Have you tried an absolute path completely outside of your directory structure, like pointing to something in your my documents folder? – John Koerner Jun 15 '12 at 17:55
  • Currently it is here: C:\TK Workspace\TK However, I've also tried in my documents and on my desktop. Neither worked. – Brandon Jun 15 '12 at 17:57