Deleting file problem


#1

Hi,


Our service picks up excel file from file system and attempting to open it, if we get any errors from open() (such as file is protected) we get an exception and than we trying to delete the file. Delete() throws an exception saying that the file is “being used”.
I do not see any Close() in Excel object. What should we do?

Here is a simple C# form sample to see the problem. (does not have to be a service)
Take any excel file and make it password protected or anything else to cause Open() to fail with an exception


private void button2_Click(object sender, System.EventArgs e)
{
string fIn = textBox1.Text;
Excel excel1 = new Excel();
try
{
excel1.Open(fIn);
}
catch(Exception ex)
{
string x = ex.Message;
}
finally
{
try
{
File.Delete(fIn);
}
catch(Exception ex1)
{
string x2 = ex1.Message;
}
}
}




#2

Dear Mark,

Yes. If an exception is thrown, I should close it internally. I have fixed it. Thanks for your feedback.

Because I am doing some other enhancement, I will release it within one week. Now thanks for your patience.

If you’re too urgent to wait for it please let me know.