So I'm working on a project that uses an excel file to add "descriptions to user controls. As of right now, my code opens the excel file using an absolute path, like so
Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(@"C:\absolute path\filename.xlsx", Type.Missing, Type.Missing
, Type.Missing, Type.Missing, Type.Missing, Type.Missing
, Type.Missing, Type.Missing, Type.Missing, Type.Missing
, Type.Missing, Type.Missing);
which works just fine.
I then tried renaming the file (just to make sure that the C:\ file wasn't being opened for some odd reason) and added it to my project so that I wouldn't have to depend on being able to access a particular drive (i.e the file could be opened because it's associated with the project). Then I tried the following code:
Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(@"newfileName.xlsx", Type.Missing, Type.Missing
, Type.Missing, Type.Missing, Type.Missing, Type.Missing
, Type.Missing, Type.Missing, Type.Missing, Type.Missing
, Type.Missing, Type.Missing);
which gave me this:
"Additional information: 'newfileName.xlsx' could not be found. Check the spelling of the file name, and verify that the file location is correct."
I was wondering what is the correct way to add an excel file to a project and open it using a relative path name?