Hi,
In my application i am using a third party tool to show an uploaded excel sheet and to edit and save it. During this process i need to delete the existing excel sheet and edit and save new excel sheet. I have tried to delete but the excel will not delete and throw error as excel sheet in use by another process cannot delete. So i decided to close that excel sheet or kill the process so i wrote code as below:
using Excel = Microsoft.Office.Interop.Excel;
Excel.ApplicationClass _Excel;
Excel.Workbook WB;
Excel.Worksheet WS;
try
{
_Excel = new Microsoft.Office.Interop.Excel.ApplicationClass();
WB = _Excel.Workbooks.Open(@"FIENAME",
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);
WB.Close(false , Type.Missing, Type.Missing);
}
catch (Exception ex)
{
WB.Close(false, Type.Missing, Type.Missing);
throw;
}
finally
{
GC.Collect();
GC.WaitForPendingFinalizers();
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(WB);
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(_Excel);
}
but this will still throw same error that the excel sheet is being used by another process... Can u please help me how can we close that excel or workbook programatically. Or what programatic solution this can have.. as killing process might effect other projects in Server...
Please help!! Thanking You in advance!!