-
Sep 16th, 2023, 08:17 AM
#1
Thread Starter
Junior Member
FileSystemWatcher.Changed event get triggred when shared excel file gets closed
I'm using the FileSystemWatcher.Changed event in my VB.NET application to track changes in files, mainly Excel files. I have used NotifyFilters.LastWrite Or NotifyFilters.Attributes.
I have observed that the Changed event gets triggered when shared Excel files are closed, which does not happen in the case of non-shared Excel files.
I wanted to know if there is any specific reason behind this behavior and if there is a way to check if the Changed event got triggered because of closing the file. I have checked other forums and did not find any relevant cases and solutions.
Also, I wanted to know if there is a way to trigger the Changed event only when changes are made to the Excel files or when the Excel files are saved.
Sample code:
Sub New()
Dim watcher As New FileSystemWatcher
watcher.Path = "E:\FSW"
watcher.NotifyFilter = NotifyFilters.LastWrite Or NotifyFilters.Attributes
watcher.Filter = "*.*"
AddHandler watcher.Changed, AddressOf File_Changed
watcher.EnableRaisingEvents = True
End Sub
Private Sub File_Changed(ByVal source As Object, ByVal e As FileSystemEventArgs)
Console.WriteLine($"Changed event occured Name: {e.Name}, FullPath:{e.FullPath}, ChangeType:{e.ChangeType}")
End Sub
Last edited by IT_Researcher; Sep 17th, 2023 at 11:39 PM.
-
Sep 25th, 2023, 01:21 AM
#2
Re: FileSystemWatcher.Changed event get triggred when shared excel file gets closed
If (and from your description it sounds like that) this is common excel behavior, then there is probably nothing you can do about it.
It makes sense that excel writes the Share information (Who has the workbook open now) to the file and removes it when the shared file is closed.
For such files, you would need to further examine the file when FileSystemWatcher.Changed fires to determine if there really was a change.
-
Sep 25th, 2023, 09:28 AM
#3
Re: FileSystemWatcher.Changed event get triggred when shared excel file gets closed
Just so we are on the same page, what do you mean by, "shared Excel files"?
-
Oct 6th, 2023, 01:28 PM
#4
Re: FileSystemWatcher.Changed event get triggred when shared excel file gets closed
He meant Excel files in a shared network folder. A lock file is created in the same folder when an Excel file is opened so that if other users try to open it, it only opens in read-only mode. When the initial users close the file, the lock file is deleted automatically.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Oct 6th, 2023, 04:09 PM
#5
Re: FileSystemWatcher.Changed event get triggred when shared excel file gets closed
 Originally Posted by stanav
He meant Excel files in a shared network folder. A lock file is created in the same folder when an Excel file is opened so that if other users try to open it, it only opens in read-only mode. When the initial users close the file, the lock file is deleted automatically.
Unlikely. Excel has an option to create a shared workbook that allows multiple people to have it open at the same time, each one making their own changes to it. In older versions of Excel, this was enabled through the Tools->Share Workbook menu item. You could then configure things like when updates made by others become visible to you, or how to handle cases where you and another user modify the same field(s). I would bet an enormous amount of money that is what the OP is referring to.
Edit to add: And it is probably the behind the scenes file level stuff that allows Excel to function with multiple people accessing the same file at the same time that is causing the FileChanged event to trigger, since I'm sure that Excel is storing information inside the file about who else has it open, and that needs to be updated when someone closes the workbook, even if they didn't make manual changes to it.
Last edited by OptionBase1; Oct 6th, 2023 at 04:13 PM.
-
Oct 6th, 2023, 04:52 PM
#6
Re: FileSystemWatcher.Changed event get triggred when shared excel file gets closed
I suspect it's the truly shared file, as well. Though it's mighty nice to see Stanav drop by
Co-editing has become so common for spreadsheets, perhaps starting with Google Docs, that MS pretty much had to add the functionality into Excel. Most likely the file really IS changing. After all, an xlsx isn't really a file at all. It's really a zipped directory tree. What is in that tree? Well, there's quite a lot, really. Most likely one of the directories holds a bunch of information that facilitates the sharing. That directory may not even exist, or may not be used, for single use. That's just a guess, though, I've never really wandered around in that directory tree much, just looked at the size of the thing, checked out a couple files...then fled.
My usual boring signature: Nothing
 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|