The process cannot access ‘’ because it is being used by another process - error in .NET

Hi,

I am using 7.0.2.0 Aspose.Cells for.net.

Workbook w = new Workbook(filepath);

w.save(filepath);

After a second again if same file path goes, it gives an below error

The process cannot access the file ‘’ because it is being used by another process.

How can we save and close/dispose the file?

Thanks,

Nikhil Pardhe

Hi,


Thanks for providing us some details.

Please note, when Aspose.Cells re-saves the workbook, it creates a new file, it means the contents of older file are deleted or overwritten with the same name. So, suppose if some file say “Sample.xlsx” is already opened by another process or opened in MS Excel, then Aspose.Cells will not be able to re-save the file and it will give exception saying:
e.g
The process cannot access ‘…\Sample.xlsx’ because it is being used by another process.

So, you must release Sample.xlsx file from other process or from Excel first, so, Aspose.Cells could save the file with the same name. Alternatively, you may re-save the file by different name (e.g “Sample1.xlsx”).

Thank you.

Thanks for you quick response!

I completely got your point.

There are no excel application running in my task manager prior to running aspose code but when I save the file using below code

Workbook w = new Workbook(filepath); //sample.xls
w.save(filepath);

the excel file (sample.xls) process stays open in task manager meaning it is not being close.
and If I again run the same code using sample.xls file it will throw the same error.

I am looking for solution to close the excel file after processing is done.

In Microsoft.Office.Interop.Excel we have follwing options to close and quit the excel

excelApp.Workbooks.Close();
excelApp.Quit();

Hi,

It looks very strange as you got this issue, we do not find this issue at all. The issue does not seem to me related to Aspose.Cells APIs rather it is specific to your pc or some processes/applications you have started. Please note, Aspose.Cells has Workbook.Dispose method to manually free the resources, etc. which has been added in newer versions, therefore if you are using any older version of the API, please upgrade to latest version in order to use this method. Also, you may give the following line of code a try at the end if it makes any difference:
e.g
Sample code:

w = null;

If you still find the issue, kindly create a simple console application with our latest version/fix (v17.3.x) to reproduce the issue on our end, we will check it soon.
Note: To evaluate your issue precisely, we got to reproduce it on our end first.

Thank you.

I tried using latest version still getting same error.

Hi,


I am afraid, we might not provide you much help as we need to first reproduce the issue on our end. As requested earlier, please create a sample project (runnable) with our latest version/fix (v17.3.x) to reproduce the issue on our end, you may zip the project prior attaching here, we will check it soon.

Thank you.

Hi team,
I am using Aspose.cells Version : 19.8.0 . Today i am also facing same kind of issue.Although it was working fine before. This file is not opened anywhere nor excel application is open…

Code used to save:

var filePath = Path.Combine(Path.GetTempPath(), fileName);
wb.Save(filePath);

Error:
The process cannot access the file ‘C:\\windows\\TEMP\\RateSheetTemplate_20200909.xlsx’ because it is being used by another process.

Is there any way to solve this ?

@RenukaH,

I guess your file “RateSheetTemplate_20200909.xlsx” might be opened in the background by some process, MS Excel or application (for which you do not know about it). So, you must release the file from other processes/applications, so, Aspose.Cells could save the file fine.

By the way, could you try to save/re-save the file by different name (e.g “RateSheetTemplate_20200909_1.xlsx”) if it works or not?

@Amjad_Sahi
On server there was no process using this document.
I deleted the saved file with same name and tried again…Its working fine now…

But I am looking for safe solution if this happen again in future.

@RenukaH,

Maybe you have some multi-threaded applications or environment which are using the file and multiple requests are saving/accessing the same file. Anyways, this is not an issue with Aspose.Cells APIs. Also, to provide a solution to your issue, we need to reproduce it on our end first and set it as a bug.

I am processing many files, sequentially. After doing Document.Save on all of them, I then need to open the pdfs and move them. Getting this “process cannot access because being used by another process” error. Please provide a way to release/dispose the handle/object

@ksheeley,

Which Aspose API you are using? Are you using Aspose.PDF?