none
复制文件 RRS feed

答案

  • void Scenario7::CopyFileButton_Click(Object^ sender, RoutedEventArgs^ e)
    {
        rootPage->ResetScenarioOutput(OutputTextBlock);
        StorageFile^ file = rootPage->SampleFile;
        if (file != nullptr)
        {
            // Get the returned file and copy it
            StorageFolder^ documentsFolder = KnownFolders::DocumentsLibrary;
            create_task(file->CopyAsync(documentsFolder, "sample - Copy.dat", NameCollisionOption::ReplaceExisting)).then([this, file](task<StorageFile^> task)
            {
                try
                {
                    StorageFile^ sampleFileCopy = task.get();
                    OutputTextBlock->Text = "The file '" + file->Name + "' was copied and the new file was named '" + sampleFileCopy->Name + "'.";
                }
                catch(COMException^ ex)
                {
                    rootPage->HandleFileNotFoundException(ex);
                }
            });
        }
    }

    Hello Win8Newer:

    你可以去下载MSDN示例程序来参考:

    FileAccess Sample

    2013年1月17日 4:29

全部回复

  • void Scenario7::CopyFileButton_Click(Object^ sender, RoutedEventArgs^ e)
    {
        rootPage->ResetScenarioOutput(OutputTextBlock);
        StorageFile^ file = rootPage->SampleFile;
        if (file != nullptr)
        {
            // Get the returned file and copy it
            StorageFolder^ documentsFolder = KnownFolders::DocumentsLibrary;
            create_task(file->CopyAsync(documentsFolder, "sample - Copy.dat", NameCollisionOption::ReplaceExisting)).then([this, file](task<StorageFile^> task)
            {
                try
                {
                    StorageFile^ sampleFileCopy = task.get();
                    OutputTextBlock->Text = "The file '" + file->Name + "' was copied and the new file was named '" + sampleFileCopy->Name + "'.";
                }
                catch(COMException^ ex)
                {
                    rootPage->HandleFileNotFoundException(ex);
                }
            });
        }
    }

    Hello Win8Newer:

    你可以去下载MSDN示例程序来参考:

    FileAccess Sample

    2013年1月17日 4:29
  • 谢谢
    2013年1月17日 4:44