in archived/Clipboard/cpp/CopyFiles.xaml.cpp [94:193]
void CopyFiles::PasteButton_Click(Object^ sender, RoutedEventArgs^ e)
{
OutputText->Text = "";
// Get data package from clipboard
DataPackageView^ dataPackageView = DataTransfer::Clipboard::GetContent();
if (dataPackageView->Contains(StandardDataFormats::StorageItems))
{
create_task(dataPackageView->GetStorageItemsAsync()).then(
[this, dataPackageView](task<IVectorView<IStorageItem^>^> itemsTask)
{
IVectorView<IStorageItem^>^ storageItems;
try
{
storageItems = itemsTask.get();
}
catch (Exception^ ex)
{
rootPage->NotifyUserBackgroundThread("Failed GetStorageItemsAsync - " + ex->Message, NotifyType::ErrorMessage);
}
if (storageItems != nullptr)
{
rootPage->NotifyUserBackgroundThread("Pasting " + storageItems->Size + " file(s):\n", NotifyType::StatusMessage);
OutputText->Text += "Requested Operation: ";
switch (dataPackageView->RequestedOperation)
{
case DataPackageOperation::Copy:
{
OutputText->Text += "Copy \n\n";
}
break;
case DataPackageOperation::Link:
{
OutputText->Text += "Link \n\n";
}
break;
case DataPackageOperation::Move:
{
OutputText->Text += "Move \n\n";
}
break;
case DataPackageOperation::None:
{
OutputText->Text += "None \n\n";
}
break;
default:
break;
}
// Iterate through each element in the storageitem vector.
std::for_each(begin(storageItems), end(storageItems),
[this](IStorageItem^ item)
{
if (item->IsOfType(StorageItemTypes::File))
{
StorageFile^ file = safe_cast<StorageFile^>(item);
// Copy the file
create_task(file->CopyAsync(ApplicationData::Current->LocalFolder, file->Name, NameCollisionOption::ReplaceExisting)).then(
[=](task<StorageFile^> copiedTask)
{
StorageFile^ copiedFile;
try
{
copiedFile = copiedTask.get();
}
catch (Exception^ ex)
{
rootPage->NotifyUserBackgroundThread("Failed CopyAsync - " + ex->Message, NotifyType::ErrorMessage);
}
if (copiedFile)
{
OutputText->Text += "File: " + copiedFile->Name + " was copied from " + file->Name + "\n";
}
});
}
else
{
// Skipping folders for brevity sake.
OutputText->Text += item->Path + " is a folder, skipping \n";
}
});
}
});
}
else
{
rootPage->NotifyUser("StorageItems format is not available in clipboard", NotifyType::StatusMessage);
}
}