Filesystemwatcher prevents file writes

  • Thread starter Thread starter John Wright
  • Start date Start date
J

John Wright

I am trying to set up my program to prevent a file from being written to. I
have an INI file that cannot be changed and I want to prevent anyone but my
program from changing it. I have set up the filesystemwatcher to notify me
of changes, but if I don't want a change to take place I want to prevent the
changes from taking place. Is there an event that fires when the file is
being accessed that I can write code to lock the file? Does anyone have any
idea how to lock a file from being changed if my program denigns access?

John
 
Hi,
I am trying to set up my program to prevent a file from being written to. I
have an INI file that cannot be changed and I want to prevent anyone but my
program from changing it. I have set up the filesystemwatcher to notify me
of changes, but if I don't want a change to take place I want to prevent the
changes from taking place. Is there an event that fires when the file is
being accessed that I can write code to lock the file? Does anyone have any
idea how to lock a file from being changed if my program denigns access?

FileSystemWatcher won't help.

You may open the file in exclusive mode and keep it open until the app
terminates. Use the FileStream(path, FileMode, FileAccess, FileShare)
constructor with FileShare.Read.

bye
Rob
 
Back
Top