1

I'm working on Windows phone 8 store app and need to Zip a Local StorageFolder (with some images). Environment VS 2013. I learned that I can add references to SharpCompress & System.IO.Compression (but not .FileSystem) only.

SharpZipLib & DotNetZip don't seem to support WP8.

The examples given by SharpCompress don't work.

Any suggestion with a code will help a lot. Thanks.

4

1 回答 1

0

System.IO.压缩:

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);
                                            }
                                        }
                                    }
                                }
                            }
                        }
于 2014-02-06T14:58:34.590 回答