Zip a folder in C++/Cx UWP application RRS feed

  • Question

  • I am working on UWP C++/Cx app and need to create zip file for all files in a folder. I use FileSavePicker, StorageFile and Windows::Storage::Compression::Compressor. Here are the code 

    auto savePicker = ref new FileSavePicker();  
    auto file = co_await savePicker->PickSaveFileAsync();
    if (file != nullptr)
     wstring subFolder = L"Plans";
     auto planFolder = co_await ApplicationData::Current->LocalFolder->GetFolderAsync(StringUtility::From(subFolder));
     auto planFiles = co_await planFolder->GetFilesAsync();
     unsigned int zipIndex = 0;
     IRandomAccessStream^  zipStream  = co_await file->OpenAsync(FileAccessMode::ReadWrite);
     IOutputStream^ outStream = zipStream->GetOutputStreamAt(zipIndex);
     Windows::Storage::Compression::Compressor^ compressor = ref new Windows::Storage::Compression::Compressor(outStream);
     for (StorageFile^ planFile : planFiles)
       Buffer^ bufRead = co_await FileIO::ReadBufferAsync(planFile);
       auto result =  co_await compressor->WriteAsync(bufRead);
       auto bSuccess = co_await compressor->FlushAsync();                 
       zipIndex += bufRead->Length;
     auto opOK = co_await compressor->FinishAsync();

    I could create compressed file, however it cannot be unzipped (Invalid). I found discussions about using ZipFile and ZipArchive. But those classes are NOT available in C++/Cx. Any suggestions? Thanks!

    Tuesday, August 6, 2019 1:44 AM

All replies

  • Hi,
    The ZipFile and ZipArchive are not supported in C++/CX. If you want to unzip the file,you could use Decompressto unzip.Here is a C# sample you could refer to. 

    Best Regards,
    Tuesday, August 6, 2019 6:35 AM
  • Thanks Fay, I have looked at the same sample while writing my code. I thought that ZipFile and ZipArchive are not supported in C++/CX, and thanks for the confirmation.
    Tuesday, August 6, 2019 5:32 PM
  • Hi,

    Yes, it is indeed like this.

    Best Regards,


    Wednesday, August 7, 2019 3:00 AM