I'm using visual studio 2008 to create a console application on c#.
The application "reads" an excel file 97-2003 (.XLS).
I'm using jet to read the file:
OleDbConnection oConn = new OleDbConnection();
oConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + file_path + " ;Extended Properties=\"Excel 8.0;HDR=No;IMEX=1\";";
But when running the program I get error "External table is not in the expected format."
I have tried reading the excel file with the NPOI library and i got error:
Message = "Invalid header signature; read 0x0010000000060809, expected 0xE11AB1A1E011CFD0"
So, it's like the file is invalid in some way.
If, through Windows, I open the excel file on Office Excel, then save it with the same and same extension .xls overwriting it , and after that I run the console application, then the application runs fine with no error.
So, what I would like to do is: with c# code, open the file and save it and overwrite it, so the application could read the file successfully.
I guess I could open the file like this:
File.OpenWrite(file_path);
But how could I overwrite the file?