1

how would a monitor just a particular file in AppData folder.

I've tried using StorageFolderQueryResult.ContentsChanged event to handle this, but this one actually callbacks for any changes through the folder.

My problem is to just a monitor a single file and use the eventhandler when its changed.

I've tried to use this "UserSearchFilter" property to QueryOptions. That didnt work actually.

cAn someone help with this ? It would also be helpful if you could additionally provide the syntax for the whole problem.

My contentschanged event is not firing on modifying the "filename" in the folder.

     auto fileTypeFilter = ref new Platform::Collections::Vector<Platform::String^>();
fileTypeFilter->Append("*");

auto queryOptions = ref new QueryOptions(CommonFileQuery::OrderBySearchRank, fileTypeFilter);
//use the user's input to make a query
queryOptions->UserSearchFilter = InputTextBox->Text;
auto queryResult = musicFolder->CreateFileQueryWithOptions(queryOptions);


auto localFolder = ApplicationData::Current->LocalFolder;
auto currPath = localFolder->Path;
auto fileTypeFilter = ref new Platform::Collections::Vector<Platform::String^>();
fileTypeFilter->Append(".dat");

auto queryOptions = ref new QueryOptions(CommonFileQuery::OrderByName, fileTypeFilter);
//use the user's input to make a query
queryOptions->UserSearchFilter = L"filename";
auto queryResult = localFolder->CreateFileQueryWithOptions(queryOptions);
queryResult->ContentsChanged += ref new TypedEventHandler<IStorageQueryResultBase^,        Platform::Object^>(this, &Scenario1::OnLocalAppDataChanged);
     //find all files that match the query
 create_task(queryResult->GetFilesAsync()).then([this, queryOptions]    (IVectorView<StorageFile^>^ files)
    {
        String^ outputText = "";
        //output how many files that match the query were found
        if ( files->Size == 0)
     {
         outputText += "No files found for '" + queryOptions->UserSearchFilter + "'";
    }
    else if (files->Size == 1)
    {
        outputText += files->Size.ToString() + " file found:\n\n";
    }
    else
    {
        outputText += files->Size.ToString() + " files found:\n\n";
    }
    //output the name of each file that matches the query
    for (unsigned int i = 0; i < files->Size; i++)
    {
        outputText += files->GetAt(i)->Name + "\n";
    }
    OutputTextBlock->Text = outputText;
});
}
void Scenario1::OnLocalAppDataChanged(Windows::Storage::Search::IStorageQueryResultBase^ sender, Platform::Object^ args)
{
Platform::String^ hello = L"hello world, I'm called back";
}
minu
  • 117
  • 1
  • 1
  • 6

1 Answers1

-1

You have to call the method GetFilesAsync() at least once, otherwise the event will never fire.

Add

queryResult->GetFilesAsync();

before

queryResult->ContentsChanged += ref new TypedEventHandler<IStorageQueryResultBase^,...

I know you don't really need the files at that point, but that's the offical way the ContentsChanged event should be used. Have a look at the first paragraph of the documentation.

Serjik
  • 10,543
  • 8
  • 61
  • 70