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
これだけのためにライブラリを使用したいことに注意してください。