locked
file pickers

    Question

  • 
    i want to pick multiple files at the same time, store all of them in app's private memory and retrieve them all at the same time when time comes... 
    How can i achieve that??
    Thursday, August 1, 2013 9:33 AM

Answers

All replies

  • Hi,meesun

    I think FileOpenPicker.PickMultipleFilesAsync is the method you are finding.This method shows the file picker so that the user can pick multiple files.It returns a filePickerSelectedFilesArray object that contains all the files that were picked by the user. Picked files in this array are represented by storageFile objects.

    Below is a sample for how to use it

    rootPage->ResetScenarioOutput(OutputTextBlock);
    
        if (rootPage->EnsureUnsnapped())
        {
            FileOpenPicker^ openPicker = ref new FileOpenPicker();
            openPicker->ViewMode = PickerViewMode::List;
            openPicker->SuggestedStartLocation = PickerLocationId::DocumentsLibrary;
            openPicker->FileTypeFilter->Append("*");
    
            create_task(openPicker->PickMultipleFilesAsync()).then([this](IVectorView<StorageFile^>^ files)
            {
                if (files->Size > 0)
                {
                    String^ output = "Picked files:\n";
                    std::for_each(begin(files), end(files), [this, &output](StorageFile ^file)
                    {
                        output += file->Name + "\n";
                    });
                    OutputTextBlock->Text = output;
                }
                else
                {
                    OutputTextBlock->Text = "Operation cancelled.";
                }
            });
        }

    And if you have any question about this method please see below.

    Below is the link:

    http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.pickers.fileopenpicker.pickmultiplefilesasync.aspx?cs-save-lang=1&cs-lang=cpp#code-snippet-1

    And below is a sample fore this method:

    http://code.msdn.microsoft.com/windowsapps/File-picker-sample-9f294cba

    Best Regard!



    Friday, August 2, 2013 2:02 AM
    Moderator
  • Thank u Xiaoliang Chen!!!

    Actually i achieved picking multiple files. i need help with storing them in a location( in app's private memory or in any other location in the system) and retrieving them back later. I want to pick all those stored files back and upload them after sometime. 

    Saturday, August 3, 2013 5:30 AM
  • Hi,meesun

    Do you mean after get them, you want to place them together?  And find them & upload them after somtime convenient?

    Below code could help you place them in a specified folder.

     rootPage->ResetScenarioOutput(OutputTextBlock);
    
        if (rootPage->EnsureUnsnapped())
        {
            FileSavePicker^ savePicker = ref new FileSavePicker();
            savePicker->SuggestedStartLocation = PickerLocationId::DocumentsLibrary;
    
            auto plainTextExtensions = ref new Platform::Collections::Vector<String^>();
            plainTextExtensions->Append(".txt");
            savePicker->FileTypeChoices->Insert("Plain Text", plainTextExtensions);
            savePicker->SuggestedFileName = "New Document";
    
            create_task(savePicker->PickSaveFileAsync()).then([this](StorageFile^ file)
            {
                if (file != nullptr)
                {
    
                    // Prevent updates to the remote version of the file until we finish making changes and call CompleteUpdatesAsync.
                    CachedFileManager::DeferUpdates(file);
                    // write to file
                    create_task(FileIO::WriteTextAsync(file, file->Name)).then([this, file]()
                    {
                        // Let Windows know that we're finished changing the file so the other app can update the remote version of the file.
                        // Completing updates may require Windows to ask for user input.
                        create_task(CachedFileManager::CompleteUpdatesAsync(file)).then([this, file](FileUpdateStatus status)
                        {
                            if (status == FileUpdateStatus::Complete)
                            {
                                OutputTextBlock->Text = "File " + file->Name + " was saved.";
                            }
                            else
                            {
                                OutputTextBlock->Text = "File " + file->Name + " couldn't be saved.";
                            }
                        });
                    });
                }
                else
                {
                    OutputTextBlock->Text = "Operation cancelled.";
                }
            });
        }

    And i recommend that you could create a XML file to help you manage the files you have to operate.

    Best Regard!

    Tuesday, August 6, 2013 3:28 AM
    Moderator