Excel Open Problem

MTSkull

Well-known member
Joined
Mar 25, 2003
Messages
135
Location
Boulder, Colorado
C#:
     //initialize excel objects
     //FileName is passed in from the calling function which is loaded via
     // an ini file with this value "R:\Production_Test_Files\Command_Scripts\Bootload_Test.xls"
     //When I view this value while the code is running, it changes the "\" to "\\"
     string ExWorkBook = FileName;

     //if I uncomment the next line there are no problems.
     //ExWorkBook = "R:\\Production_Test_Files\\Command_Scripts\\Bootload_Test.xls";

     Excel.Application oApp = new Excel.Application();
     //CRASHES next line with File not found error, NOTE: the Gap in the value is not present in the IDE...
     Excel.Workbook oWB = oApp.Workbooks.Open(ExWorkBook,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value);

     //Cleanup:  
     GC.Collect();
     GC.WaitForPendingFinalizers();

     oWB.Close(false,Missing.Value,Missing.Value); //Save changes = false
     Marshal.FinalReleaseComObject(oWB);
     oWB = null;
            
     oApp.Quit();
     Marshal.FinalReleaseComObject(oApp);
     oApp = null;

I have an application that reads values in from an XL spread sheet. If I pass a network path in that I read from an INI file, I get a file cannot be found error. If I place the same value into the variable locally the file opens reads and then closes just fine. I am using .net 2005.

MTS
 
Back
Top