From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to block writing to a file which is already in use?

Hi all,

There is a certain file on a network drive. Multiple users have the rights to read and write to this file.
I want to acccess this file via a LabView VI.
If someone is already accessing this file I want to create a message like "File is already in use by user XXX, therefore acccess is read-only".
Something like this is implemented in Windows (e.g. Excel...).
How can I implement this in LabView? The access from each user is done with the same VI running on different computers.
Of course I can create an .ini file, where I write the user which is currently accessing the file and block write acces for others.
Is there a better way to do this?

Thank you for any hints,
Tilman.


0 Kudos
Message 1 of 4
(2,668 Views)

I'm not sure whether this would work on a network drive, but I believe it will.

When you use the Open File function, you have an input called Deny Mode. You can use this to deny other users write access until you close the file.
I assume that if you try to open the file with write permissions after another user opened it it will return an error. You can catch this error, display the message and open the file again with read-only permissions.


___________________
Try to take over the world!
Message 2 of 4
(2,664 Views)
Thanks, tst
that's exactly what I was looking for.
It seems to work also over networks.
Now, I am trying to find out whether its possible to display which program or user is accessing the file.
If you have any ideas, please let me know.
0 Kudos
Message 3 of 4
(2,635 Views)

Does Excel tell you who is using the other file?

If yes, does it do this only for its own file types or also for files like CSV or TXT?

If it only does it for its types, then this is probably built into the definition of the file somehow (although I would assume that would mean that everytime Excel opens the file it also needs to save it?).

I would try checking in the MSDN whether this is something that Windows supports.

If not, the only option that comes to mind is the INI file you suggested.


___________________
Try to take over the world!
0 Kudos
Message 4 of 4
(2,623 Views)