zip
ステップ(アルゴリズム)を使用して両方のファイルを含めるファイルを作成することをお勧めします。
- Zipファイルを作成し、目的のファイルをzipに追加します
- アクションから必要なすべてのファイルを含むzipファイルを返します
Java構文(理解のためだけに)
FileOutputStream fos = new FileOutputStream("downloadFile.zip");
ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(fos));
zos.putNextEntry(new ZipEntry("Filename1.extension"+));
//write data in FileName1.extension
zos.write(contentBuffer1, 0, len);
zos.putNextEntry(new ZipEntry("Filename2.extension"));
//write data in FileName2.extension
zos.write(contentBuffer2, 0, len);
//write other files.....
zos.close();
ファイルが作成されたらzip
、新しく作成されたzip
ファイルをダウンロードに戻します。
return File("downloadFile.zip");
.DotNetZipを使用した同等のDOTネット
var os = new MemoryStream();
using (var zip = new ZipFile())
{
//write the first file into the zip
zip.AddEntry("file1.txt", "content1");
//write the second file into the zip
zip.AddEntry("file2.txt", "content2");
//write other files.....
zip.Save(os);
}
outputStream.Position = 0;
return File(outputStream, "application/zip", "filename.zip");
お役に立てれば!