Zip 파일 내에 zip 파일이 있고 Excel 및 PDF/Tif 문서가있는 내부 zip 파일 안에 있습니다.로컬로 저장하지 않고 zip 파일 내에 PDF를 저장하는 방법
현재 모든 파일을 읽고 데이터베이스에 저장하는 도구를 개발 중입니다. 이전에 두 파일을 모두 폴더에 저장하기 전에는 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
라이브러리를 사용하고 싶습니다.
가능한 중복/17232414/creating-a-zip-archive-in-memory-using-system-io-compression –
자신의 게시물에서 그들은 zip 파일을 만들고 있지만 zip 파일을 압축 해제하려고합니다. MemoryStream이이 작업과 관련이있을 수 있지만 여전히 수행 방법을 알고 싶습니다. –
확인 : https://stackoverflow.com/questions/20520238/how-to-read-file-from-zip-archive-to-memory-without-extracting-it-to-file-first –