Ok, here's the problem, I am using a connection using (connection .... blah blah), and then after completing my use of the block, I want to start the excel application as follows: System.Diagnostics.Process.Start (excelFile);
It works ... sometimes, sometimes my computer runs too fast and before the file is completely closed, or the connection is completely completed, or something like that, the above statement is exicuted and excel opens and says that it cannot access file.
This happens and turns off if I pause it, it works more often, but I need a way to check if I can access the file before I get it.
This does not throw an exception, so the exception cannot be thrown
I tried:
connection.Close();
connection.Dispose();
GC.Collect();
of which none worked.
I know that any check will be most similar to the possibility of returning to the fact that the file is accessible, and then before the open item can be an exicued file that is used by someone, this is fine. Just need to check.
Ok, I tried this:
Microsoft.Office.Interop.Excel.Application _app =
new Microsoft.Office.Interop.Excel.Application();
try
{
Workbook wbook = _app.Workbooks.Open(excelFile,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing);
}
catch (COMException ex)
{
}
finally
{
_app.Workbooks.Close();
GC.Collect();
}
System.Diagnostics.Process.Start(excelFile);
and I look at the exception, and then go to the start command, where excel tells me that "cannot access" fileName "