Created
June 4, 2017 12:32
-
-
Save gavilanch/31d6351fe5c2a9b6b560d6b86d0a3bab to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public FileResult Descargar() | |
{ | |
// utilizando la librería DotNetZip | |
using (ZipFile zip = new ZipFile()) | |
{ | |
// tus archivos (Puedes sacarlos de tu base de datos como arreglos de bytes) | |
var archivo1 = Server.MapPath("~/archivosDescargar/ejemplo 1.pdf"); | |
var archivo2 = Server.MapPath("~/archivosDescargar/ejemplo 2.pdf"); | |
var archivo3 = Server.MapPath("~/archivosDescargar/gavilanch2.jpg"); | |
var archivo1_nombre = Path.GetFileName(archivo1); | |
var archivo1_arregloBytes = System.IO.File.ReadAllBytes(archivo1); | |
var archivo2_nombre = Path.GetFileName(archivo2); | |
var archivo2_arregloBytes = System.IO.File.ReadAllBytes(archivo2); | |
var archivo3_nombre = Path.GetFileName(archivo3); | |
var archivo3_arregloBytes = System.IO.File.ReadAllBytes(archivo3); | |
// Esto va agregando los archivos al zip | |
zip.AddEntry(archivo1_nombre, archivo1_arregloBytes); | |
zip.AddEntry(archivo2_nombre, archivo2_arregloBytes); | |
zip.AddEntry(archivo3_nombre, archivo3_arregloBytes); | |
var nombreDelZip = "MiArchivo.zip"; | |
using (MemoryStream output = new MemoryStream()) | |
{ | |
zip.Save(output); | |
return File(output.ToArray(), "application/zip", nombreDelZip); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Gracias por tu tiempo y esfuerzo en este tutorial compañero, intente implementar este código y de acuerdo a la documentación la clase ZipFile es una clase de tipo estática ademas los métodos no existen, bueno supongo q' son actualizaciones de clases.
De igual manera muchas gracias.