Search code examples
c#asp.netspreadsheetgear

Spreadsheetgear Maintains Lock on File


Through an C#/ASP.NET website, I'm using SpreadsheetGear to open a file from a template, then making modifications to it based off user input and then saving it a new location. When I attempt to manually open the newly created file after saving, I get a message stating that SpreadsheetGear has the file locked for editing.

Here's code snippets below:

SpreadsheetGear.IWorkbook workbook = SpreadsheetGear.Factory.GetWorkbook(pathToTemplate);
workbook.WorkbookSet.GetLock();
SpreadsheetGear.IWorksheet worksheet = workbook.Worksheets["sheetName"];
SpreadsheetGear.IRange cells = worksheet.Cells;

//fill in worksheet
...

workbook.SaveAs(pathToGeneratedFiles + exportFileName, SpreadsheetGear.FileFormat.XLS97);
workbook.WorkbookSet.ReleaseLock();

worksheet = null;
workbook.Close();
workbook = null;

The only thing I can think of in the undisplayed "fill in worksheet" section that is even somewhat tricky is deleting a column and shifting the other columns to the left.

Any thoughts? Thanks.


Solution

  • So, it turned out to an old copy of the SpreadsheetGear DLL in my project's bin folder. Once we updated it, the problem went away. Thanks for the help.