0

私はAsp.NetでWebアプリケーションを開発しており、SharpZipLibを使用してodtファイル(Open Officeから)と将来のdocxファイル(ms office用)を操作しています。odt ファイル (zip ファイルなど) を開き、その中の xml ファイルを変更し、再度 zip して、クライアントに送信するブラウザーに渡す必要があります。

ファイルシステムでこれを行うことができますが、一時的にディスクにスペースができてしまい、必要ありません。これをメモリ内で(MemoryStreamクラスを使用して)実行したいのですが、SharpZipLibを使用してメモリストリーム内のフォルダー/ファイルを解凍し、変更して使用して再度圧縮する方法がわかりません。これを行う方法についてのサンプルはありますか?

ありがとうございました

4

1 に答える 1

0

次のようなものを使用できます

 Stream inputStream = //... File.OpenRead(...);

  //for read file
 ZipInputStream zipInputStream = new ZipInputStream(inputStream));

 //for output 
 MemoryStream memoryStream  = new MemoryStream();



using ( ZipOutputStream zipStream = new ZipOutputStream(memoryStream))
{




          ZipEntry entry = new ZipEntry("...");
          //...

          zipStream.PutNextEntry(entry);
          zipStream.Write(data, 0, data.Length);
          //...


          zipStream.Finish();
          zipStream.Close();

}

編集 ::

一般に、ファイルを解凍し、 ZipEntry を取得し、 を変更し、MemoryStream を使用して ZipOutputStream に書き込む必要があります。この記事を使用http://www.codeproject.com/KB/cs/Zip_UnZip.aspx

于 2011-11-22T12:16:45.933 に答える