I create an Excel file using EPPlus library. After the file is created, it cannot be deleted or edited, as it is said to be used by "another user", as long as the program is running. I cannot find any solution that would work for me.
```
Here is my code:
var newFile = new FileInfo(path);
using (var xlPackage = new ExcelPackage(newFile))
{
var ws = xlPackage.Workbook.Worksheets.Add("Sheet1");
...
xlPackage.Save();
}
```
The strange thing is that I am able File.Delete() the newly created files from within my code. But I cannot delete or edit it while the program is still running from the Windows Explorer.
Comments: Thank you for your answer. But the program runs as Windows Service, so it would not stop. What could you suggest in such a situation?
```
Here is my code:
var newFile = new FileInfo(path);
using (var xlPackage = new ExcelPackage(newFile))
{
var ws = xlPackage.Workbook.Worksheets.Add("Sheet1");
...
xlPackage.Save();
}
```
The strange thing is that I am able File.Delete() the newly created files from within my code. But I cannot delete or edit it while the program is still running from the Windows Explorer.
Comments: Thank you for your answer. But the program runs as Windows Service, so it would not stop. What could you suggest in such a situation?