diff --git a/Zip.cs b/Zip.cs index 7e3aa9b..ef84e00 100644 --- a/Zip.cs +++ b/Zip.cs @@ -144,29 +144,33 @@ public static class Zip public static byte[] ComprimirArchivos(Dictionary archivos) { - string tempZip = Path.GetTempFileName(); + // Crear un nombre de archivo temporal que NO exista + string tempFileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".zip"); - using (var zip = ZipFile.Open(tempZip, ZipArchiveMode.Create)) + using (ZipArchive zip = ZipFile.Open(tempFileName, ZipArchiveMode.Create)) { - foreach (var kv in archivos) + foreach (var archivo in archivos) { - var entry = zip.CreateEntry(kv.Key, CompressionLevel.Optimal); - using (var entryStream = entry.Open()) + var entry = zip.CreateEntry(archivo.Key, CompressionLevel.Optimal); + using (Stream stream = entry.Open()) { - byte[] data = kv.Value; - entryStream.Write(data, 0, data.Length); + byte[] data = archivo.Value; + stream.Write(data, 0, data.Length); } } } - byte[] resultado = File.ReadAllBytes(tempZip); - try { File.Delete(tempZip); } catch { } - return resultado; + byte[] result = File.ReadAllBytes(tempFileName); + + try { File.Delete(tempFileName); } catch { } + + return result; } + public static byte[] ComprimirArchivos(Dictionary archivos) { - string tempZip = Path.GetTempFileName(); + string tempZip = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".zip"); using (var zip = ZipFile.Open(tempZip, ZipArchiveMode.Create)) { diff --git a/tsZip.NS.csproj b/tsZip.NS.csproj index 53590f1..4534b27 100644 --- a/tsZip.NS.csproj +++ b/tsZip.NS.csproj @@ -10,11 +10,12 @@ netstandard2.0 tsZip.NS netstandard2.0, libreria - 1.0.0 + 1.0.1 Manuel Tecnosis S.A Utilidades de compresión + - 2026-05-25 Correcciones en crear ficheros - 2026-05-14 Versión 5 Regeneración completa de la clase con copilot