Reputation: 2617
Does Excel.Workbook.SaveAs() put a lock on the file? If not, how would I force a lock on the file while it's saving?
I'm writing a Windows Service that runs on multiple machines. The Windows Service writes Excel files to a shared mount. I want to make sure that the Excel file is locked while saving so another process is not able to write to it until the file is closed by the first process.
Upvotes: 1
Views: 704
Reputation: 172468
When you will save the file the file will be locked so no one has the access to open it. It will be locked. Are you looking for something like this:
workbook.SaveAs(filename, AccessMode: XlSaveAsAccessMode.xlExclusive);
You may also check XlSaveAsAccessMode Enumeration
Specifies the access mode for the Save As function.
Upvotes: 1