2026-05-25 Correcciones en crear ficheros

This commit is contained in:
2026-05-25 10:55:58 +02:00
parent 97a439fc34
commit 046fc7a1c1
2 changed files with 17 additions and 12 deletions

26
Zip.cs
View File

@@ -144,29 +144,33 @@ public static class Zip
public static byte[] ComprimirArchivos(Dictionary<string, byte[]> 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<string, Stream> archivos)
{
string tempZip = Path.GetTempFileName();
string tempZip = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".zip");
using (var zip = ZipFile.Open(tempZip, ZipArchiveMode.Create))
{