How to capture file open events?


hi,

i create solution logs when user in windows open file. (like xlsx or txt file etc). both windows explorer or within related application).

filesystemwatcher doesn’t work because doesn’t capture file opened other application. captures create/change/delete events, not “open” event.

is there way in .net/c# capture event?

erik lidman


if wanna check if file opened or not, there no in-built function so.

here example check:

private bool checkfileopened(string path) {     try     {         using (stream stream = new filestream(path, filemode.open))         {             //file not opened!                      }     }      catch      {        //check here why failed , ask user retry if file in use.              return true;     }     return false; }   //check like: bool bcheck = checkfileopened(@"c:\myfile.txt"); if(bcheck) {     //file opened } else {    //file not opened }


mitja



Visual Studio Languages  ,  .NET Framework  >  Visual C#



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

job syspolicy_purge_history job fail in sqlserver 2008

Trying to register with public marketplace error with 'Get-AzureStackStampInformation'