Picture folder Monitor API in metro app


  • Picture folder Monitor API in metro app ?

    Recently  i encountered a problem and needs to monitor the Pictures folder, I haven't got a simple way to monitor the picture folder through windowsRT.

    Saturday, April 28, 2012 8:45 AM


All replies

  • Hi,

    FileSystemWatcher class is used to detect the file system change notifications and raise events when a directory or file changes in desktop app.

    Otherwise, you can use Win32 API FindFirstChangeNotification to watch directory change in desktop app. Here is an example Obtaining Directory Change Notifications.

    Unfortunately, both managed class FileSystemWatcher and win32 API FindFirstChangeNotification cannot be used in Metro style app.

    However, for limited functions, you can try StorageFolderQueryResult.ContentsChanged event to monitor Pictures folder.

    Best wishes,

    Robin [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, April 30, 2012 9:38 AM
  • Hi Robin,

    Thank you for your response, i use storageFolderQueryResult to monitor picture folder you refer to , but the event can't work.

    my code :

    varqueryResult = KnownFolders.PicturesLibrary.CreateFolderQuery();

    queryResult.ContentsChanged += query_ContentsChanged;

    void query_ContentsChanged(Windows.Storage.Search.IStorageQueryResultBase sender, object args)
        System.Diagnostics.Debug.WriteLine("file add in picture folder");

    thank you for your response in advance.

    Thursday, May 03, 2012 9:41 AM
  • Hi Jack,

    In the MSDN documentation, the was a user comment at the end of the StorageFolderQueryResult.ContentsChanged page that mentioned you need to call the getFoldersAsync() method on the query before the change notification callback takes effect. I'm attempting to accomplish something similar to you, and now have notifications. I'm still attempting to identify *which* files have changed. Here's an example of the code I'm using:

    public StorageFolderQueryResult _query;
    public MainPage()
        _query = KnownFolders.PicturesLibrary.CreateFolderQuery();
        _query.ContentsChanged += changeCallback;
    private void changeCallback(Windows.Storage.Search.IStorageQueryResultBase sender, object args)
        // A change has occurred, do something...
    The original page that pointed out the getFoldersAsync method:


    Wednesday, June 13, 2012 11:42 PM
  • Don't know if this thread is still active, but  StorageFolderQueryResult.ContentsChanged event seems limited to top level contents of the folder. If something changes in subfolders, the event is not raised. I tried to solve this by recursively creating queries for the entire folder hierarchy, but probably it's far from being the most efficient solution. There is also the problem of detecting when a specific files inside the folders change. I'm mostly interested in the file's DateModified attribute.

    If anyone has more insight in doing this, please let me know.


    Friday, October 05, 2012 8:15 PM
  • You need to setup QueryOptions.FolderDepth to FolderDepth.Deep, in this case query will work for sub folders too.

    Here is a code sample - http://lunarfrog.com/blog/2012/10/03/filesystem-change-notifications/

    Friday, October 05, 2012 9:09 PM
  • Thanks Andrei,

    I'll try that out. I noticed the default Windows 8 Music app immediately reacts to any file changes (ex. change the title of the song). Was wondering if Microsoft has access to some API we don't?

    Tuesday, October 09, 2012 5:30 PM
  • ContentsChanged event fires on such modifications too. But it's quite possible that Microsoft's apps have more privileges than we do.
    Tuesday, October 09, 2012 6:46 PM
  • Hey, I tried the code example from the link you posted and it's pretty much what i'm looking for except, as it is mentioned in that post, there's no way to know what exactly changed. A complete re-scan of the folder must be performed. I guess we'll have to live with that for now.

    Wednesday, October 10, 2012 2:59 PM
  • Which is a pain of course. It was really not so hard for MS to make the API more useful this time. Internally they probably use ReadDirectoryChangesW or similar and it gets a lot of informations about changes passed in. I really, really hope MS rolls out an update where the event argument contains more information than just the folder that changed.

    Beside that, the event is not always fired, so we can not rely on that. Makes implementing a cloud service app that watches your folders almost impossible. That might also be the reason why the SkyDrive app lacks change notifications entirely. You can open a file from SkyDrive within the app, change it with the program that you opened it with and the SkyDrive app will never get notified about the changes. I wonder how you do update your files in the SkyDrive app.

    Tuesday, November 06, 2012 9:21 AM
  • Seems unreliable also on Windows 8.1...

    I found when deleting more than 120 pictures in Picture Library, the event not fire... Different machine may have different result.

    If only quite a few modification, it fires successfully.

    Maybe using another thread pooling the folder modification is a better way.

    • Edited by UOW_Nick Tuesday, July 23, 2013 6:43 AM lost info
    Tuesday, July 23, 2013 6:43 AM