user2393425
user2393425

Reputation: 61

Powerbuilder: how to find the excel file already opened

I am using Powerbuilder 11.5, I want to popup the error message to the user if the particular excel file is already opened in excel. Please let me know the comment to find that.

Upvotes: 1

Views: 1226

Answers (1)

Seki
Seki

Reputation: 11465

A simple way is to try to open the file with FileOpen() with LockReadWrite! file locking (exclusive mode) :

  • if FileOpen() returns -1 the opening had fail and you can notify the user
  • if FileOpen() returned something else, juste FileClose() and continue the process

The flaw in this kind of check is that it just try to have exclusive access to the file and if the opening fails the file is probably already opened, but you cannot tell by which process / application.

The hard way would be to enumerate the processes and their files handles to check if one points to the file you are checking. Not impossible, but much more difficult to do with PowerBuilder.

Upvotes: 3

Related Questions