2014-02-06 4 views
1

을 사용하여 Windows Phone 8의 로컬 StorageFolder를 압축하십시오. Windows Phone 8 store app에서 작업 중이며 Local StorageFolder를 압축해야합니다 (일부 이미지 포함). Environment VS 2013. SharpCompress & System.IO.Compression (그러나 .FileSystem 제외)에 대한 참조 만 추가 할 수 있음을 알게되었습니다.SharpCompress 또는 Sytem.IO.Compression 또는

SharpZipLib & DotNetZip은 WP8을 지원하지 않습니다.

SharpCompress에서 제공하는 예제가 작동하지 않습니다.

코드로 제안하면 많은 도움이됩니다. 감사.

+0

방법을 사용하는 방법에 대한 [Microsoft.Bcl.Compression] (https://www.nuget.org/packages/Microsoft.Bcl.Compression) : HTTP : // www.mistergoodcat.com/post/Workingaround-a-bug-in-MicrosoftBclCompression – har07

답변

0

System.IO.Compression :

string GuidPath = Path.Combine(LocalStorage, Guid.NewGuid().ToString()) + ".zip"; 
         using (FileStream zipToOpen = new FileStream(GuidPath, FileMode.Create)) 
         { 
          using (ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Create)) 
          { 
           String[] files = Directory.GetFiles(szFldrPath); 
           foreach(String echFile in files) 
           { 
            ZipArchiveEntry readmeEntry = archive.CreateEntry(Path.GetFileName(echFile)); 
            using (BinaryWriter writer = new BinaryWriter(readmeEntry.Open())) 
            { 
             using (Stream source = File.OpenRead(echFile)) 
             { 
              byte[] buffer = new byte[4096]; 
              int bytesRead; 
              while ((bytesRead = source.Read(buffer, 0, buffer.Length)) > 0) 
              { 
               writer.Write(buffer, 0, bytesRead); 
              } 
             } 
            } 
           } 
          } 
         }