コード例 #1
0
        public bool ZipExtraer(string archivo, string directorioDestino)
        {
            Dialogo dlg = new Dialogo();

            if (archivo?.Length == 0)
            {
                archivo = dlg.DlgSeleccionarArchivo("Seleccione archivo");
            }
            else if (!File.Exists(archivo))
            {
                return(false);
            }
            if (directorioDestino?.Length == 0)
            {
                directorioDestino = dlg.DlgSeleccionarDirectorio();
            }
            if (Directory.Exists(directorioDestino) && File.Exists(archivo))
            {
                ZipFile.ExtractToDirectory(archivo, directorioDestino);
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #2
0
        public bool ZipComprimir(string archivoZip, List <string> archivos)
        {
            //List<string> lista = new List<string>();
            //lista.Add("c:\\temp\\s0-2017070611293533.wsms");
            //lista.Add("c:\\temp\\s0-2017070614023389.wsms");
            //ZipComprimir("c:\\tmp\\zip.zip", lista).ToString();
            Dialogo dlg = new Dialogo();

            if (archivoZip?.Length == 0)
            {
                archivoZip = dlg.DlgSalvarArchivo("Seleccione archivo");
            }
            if (Directory.Exists(archivos[0]))
            {
                if (File.Exists(archivoZip))
                {
                    File.Delete(archivoZip);
                }

                ZipFile.CreateFromDirectory(archivos[0], archivoZip);
            }
            else
            {
                try
                {
                    if (File.Exists(archivoZip))
                    {
                        File.Delete(archivoZip);
                    }

                    ZipArchive zip = ZipFile.Open(archivoZip, ZipArchiveMode.Create);

                    foreach (string s in archivos)
                    {
                        zip.CreateEntryFromFile(s, Path.GetFileName(s), CompressionLevel.Optimal);
                    }
                    zip.Dispose();
                    return(true);
                }
                catch
                {
                    return(false);
                }
            }
            return(true);
        }
コード例 #3
0
        public List <string> ZipLeerArchivo(string archivoZip = "none")
        {
            Dialogo dlg = new Dialogo();

            List <string> archivos = new List <string>();
            ZipArchive    zip;

            if (archivoZip != "none" && File.Exists(archivoZip))
            {
                zip = ZipFile.OpenRead(archivoZip);
            }
            else if (archivoZip != "none" && !File.Exists(archivoZip))
            {
                return(null);
            }
            else
            {
                archivoZip = dlg.DlgSeleccionarArchivo("Seleccione un archivo");

                if (archivoZip?.Length == 0)
                {
                    return(null);
                }
                else
                {
                    zip = ZipFile.OpenRead(archivoZip);
                }
            }

            foreach (ZipArchiveEntry entry in zip.Entries)
            {
                archivos.Add(entry.FullName);
            }

            return(archivos);
        }