locked
StorageFileQueryResult ContentsChanged event not firing on file moving away?

    Question

  • I've got a class in my C# app that monitors the contents of a series of StorageFolders individually using the StorageFileQueryResult class' ContentsChanged event.  I'm using FolderDepth.Deep QueryOptions. 

    • When I move a file into the folder, the event fires
    • When I copy a file into the folder, the event fires
    • When I delete a file from the folder, the event fires
    • When I move a file out of the folder, the event does not fire

    This only happens with the StorageFileQueryResult.  I have a separate set of StorageFolderQueryResults with their ContentsChanged events handled and moving a folder away seems to fire the event just fine.

    Is this a known bug? 


    Lee McPherson


    Sunday, December 28, 2014 9:03 PM

Answers

  • Hi Lee McPherson,

    >> If moving a file into a monitored folder triggers an event because the file was "created" there, why wouldn't moving a file out of a monitored folder trigger an event due to "deleting" the file?

    Based on my research, I found there were something misunderstanding about file movement. There were two scenarios about moving a file out of source folder to target folder. If the two folders were in same drive, system would cut and paste file to target folder, then the event would raise and app worked fine. But if the tow folder were in different drive, system would copy a new file to target folder, then the event would not raise and app did not work. Please check it on your side. We cannot change the second scenario, so I suggest try to work around.

    In desktop application, I know there are several properties like “last access time”, I think we can try to use these properties to achieve your requirement. Just maintains an array of object in your app, store those time properties at a particular time, refresh them using a timer, then you can know the changes in the folders. See the code sample in http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.fileproperties.basicproperties.aspx.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    Wednesday, December 31, 2014 8:13 AM
    Moderator

All replies

  • As a quick hack, I tried replacing my StorageFileQueryResults with StorageFolderQueryResults since it seems to work almost exactly the same way. However, the behavior is the same:  when the file is moved out of the folder, the ContentsChanged event is not called.

    On a side note, what's the functional difference between StorageFolderQueryResults and StorageFileQueryResults?  They seem to be almost the same thing.


    Lee McPherson

    Sunday, December 28, 2014 9:18 PM
  • It seems that the page doesn’t mention the event will fire when the file move out of folder. http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.search.aspx. Can you post some code snippets or repro project to make your situation clear?

    Monday, December 29, 2014 9:21 AM
  • Here's a repro:  http://1drv.ms/1D2FGQG

    Just select a folder using the button provided.  Snap the view (or use a second monitor) so you can see the desktop.  Then play around with adding, deleting and moving files into and out of the folder you picked using the desktop.  The app will display a status message below the button that says which files were added and which were removed by path name.


    Lee McPherson

    Monday, December 29, 2014 2:50 PM
  • Hi Lee McPherson,

    As I know, when you move a file out of a folder that means you are copying a file to the target folder. This reference http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.search.aspx shows “Apps can receive events that fire when a collection changes because files where created, modified, or deleted”.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    Tuesday, December 30, 2014 5:15 AM
    Moderator
  • If moving a file into a monitored folder triggers an event because the file was "created" there, why wouldn't moving a file out of a monitored folder trigger an event due to "deleting" the file?

    The way this ContentsChanged event works right now is not very helpful.  My app needs to monitor multiple folders (that the user selects)  for video files so that it can parse them when added or purge them from my app's listing when removed.  My app does not produce or download the videos, so I have no other way to know that files have been added/removed other than monitoring the folder. 

    I actually anticipate that the user will be moving a fair amount files around and creating folder hierarchies within these monitored folders.  So if I can't track moving files out of the monitored folder, my app breaks until they restart or trigger a ContentsChanged event from another file action.

    I'll have to instead implement a timer that periodically scans the folder contents instead.  I would guess that this might adversely affect battery life on handheld devices.


    Lee McPherson


    Tuesday, December 30, 2014 7:01 AM
  • Hi Lee McPherson,

    >> If moving a file into a monitored folder triggers an event because the file was "created" there, why wouldn't moving a file out of a monitored folder trigger an event due to "deleting" the file?

    Based on my research, I found there were something misunderstanding about file movement. There were two scenarios about moving a file out of source folder to target folder. If the two folders were in same drive, system would cut and paste file to target folder, then the event would raise and app worked fine. But if the tow folder were in different drive, system would copy a new file to target folder, then the event would not raise and app did not work. Please check it on your side. We cannot change the second scenario, so I suggest try to work around.

    In desktop application, I know there are several properties like “last access time”, I think we can try to use these properties to achieve your requirement. Just maintains an array of object in your app, store those time properties at a particular time, refresh them using a timer, then you can know the changes in the folders. See the code sample in http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.fileproperties.basicproperties.aspx.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    Wednesday, December 31, 2014 8:13 AM
    Moderator