0

zip ファイル内に zip ファイルがあり、内部の zip ファイル内に Excel と PDF/Tif ドキュメントがあります。

私は現在、これらすべてのファイルを読み取り、データベースに保存するツールを開発しています。以前は両方のファイルを最初にフォルダーに保存していましたが、zip ファイルには大量のファイルが含まれているため、ディスク容量不足の例外が発生しました。

そのため、フォルダーの場所を知らなくても、ファイルをデータベースに直接保存しようとしています。

// Path.Combine(exportPathNoZip,entry.FullName) --> \unzip\Files1\Files1.ZIP
using (ZipArchive archive = ZipFile.OpenRead(Path.Combine(exportPathNoZip,entry.FullName)))
{
    // These are the files inside the zip file and contain the Excel and the image
    foreach (ZipArchiveEntry item in archive.Entries)
    {
        // Save image to database
        if (item.FullName.EndsWith(".tif", StringComparison.OrdinalIgnoreCase) ||
            item.FullName.EndsWith(".tiff", StringComparison.OrdinalIgnoreCase) ||
            item.FullName.EndsWith(".pdf", StringComparison.OrdinalIgnoreCase))
        {
            byte[] file = File.ReadAllBytes(?????);
            _formerRepository.InsertFormerFileAsBinary(file);
        }
    }
}

ただしFile.ReadAllBytes()、パスが必要になるため、これは機能しません。それで、なにかお手伝いできますか?ファイルをローカルに保存すると、ディスク容量不足の例外が発生し、それがなければパスがありません。

System.IO.Compressionこれだけのためにライブラリを使用したいことに注意してください。

4

1 に答える 1

1

とすれば

_formerRepository.InsertFormerFileAsBinary

バイト[]を取る場合、これはうまくいくはずです:

 using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) {
        item.Open().CopyTo(ms);
        _formerRepository.InsertFormerFileAsBinary(ms.ToArray());
 }

参考までに:ストリームからのバイト配列の作成

于 2016-11-17T11:19:02.050 に答える