0

このコードは、その場で zip アーカイブを作成する便利な方法です。

(コード全体をここに投稿するのが役立つとは思いませんでした)

http://www.codeproject.com/Articles/209731/Csharp-use-Zip-archives-without-external-libraries

Response.BinaryWrite 経由でダウンロードするテキスト ファイルを圧縮するために使用しています。

これは私の実装です:

filesでありfileNames、それぞれList<string>

        // add the files to a zip
        var str = new MemoryStream();
        using (var arc = ZipArchive.OpenOnStream(str))
        {
            for (int i = 0; i < files.Count(); i++)
            {
                using (var fs = arc.AddFile(fileNames[i]).GetStream(FileMode.Open, FileAccess.ReadWrite))
                {
                    System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
                    Byte[] bytes = encoding.GetBytes(files[i]);
                    fs.Write(bytes, 0, bytes.Length);
                }
            }
        }

        result = str.GetBuffer();

        // return the zip
        return result;

私の質問は、アーカイブ内の別のフォルダーにファイルを保存する方法を誰か考えてもらえますか?

助けてくれてありがとう!

4

0 に答える 0