locked
How to get file changes in a folder CreateFileQueryWithOptions - contects changed event

    Question

  • As there is no FileSystemWatcher class for store apps, I am trying to use the Storage search options. I want to be able to get details of the changed file in a particular folder.

    I use this once I have my file open

                                    string ext = Path.GetExtension(file.Path);
                                    var options = new Windows.Storage.Search.QueryOptions { FileTypeFilter = { ext } };
                                    var query = Negatives.CreateFileQueryWithOptions(options);                           
                                    query.ContentsChanged += query_ContentsChanged;
                                    var files = await query.GetFilesAsync();

    When the ContentsChanged event fires there is nothing to indicate what file has been changed, the args are null and the sender object doesn't seem to have much

    Anyone mastered this?


    Mal

    Tuesday, March 04, 2014 1:16 PM

Answers

  • Hi Mal,

    I don't think you can query for that if there is nothing change with the file, the event only fires when an item is added to, deleted from, or modified in the folder being queried. We cannot monitor the file last open time.

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by MalBall Thursday, March 06, 2014 11:03 AM
    Thursday, March 06, 2014 10:26 AM
    Moderator

All replies

  • Hi Mal,

    If you need the files, you can get them from the variable "files".

    query.ContentsChanged += query_ContentsChanged;
    var files = await query.GetFilesAsync();
    
    foreach (var file in files)
    {
       //do something here
    }

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, March 05, 2014 9:22 AM
    Moderator
  • Hi Mal,

    If you need the files, you can get them from the variable "files".

    query.ContentsChanged += query_ContentsChanged;
    var files = await query.GetFilesAsync();
    
    foreach (var file in files)
    {
       //do something here
    }

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Yes thanks, I have moved on a bit and worked this out. I can now get details of changes, my real problem now is that the file has been opened by another application using an association, and if the file is closed by that app without doing any changes I don't know anything about it.

    With the desktop app I have developed, I fire up the external app using a process within my app and I know when the process has been closed and can take the appropriate action. Unfortunately this isn't available in a store app so I am a bit stumped


    Mal

    Wednesday, March 05, 2014 9:27 AM
  • Hi Mal,

    I don't think you can query for that if there is nothing change with the file, the event only fires when an item is added to, deleted from, or modified in the folder being queried. We cannot monitor the file last open time.

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by MalBall Thursday, March 06, 2014 11:03 AM
    Thursday, March 06, 2014 10:26 AM
    Moderator
  • Hi Mal,

    I don't think you can query for that if there is nothing change with the file, the event only fires when an item is added to, deleted from, or modified in the folder being queried. We cannot monitor the file last open time.

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    Yes as I thought, I will mark this as answered but if anyone sees this and can suggest a way round the issue I would be grateful

    Mal

    Thursday, March 06, 2014 11:03 AM