Salve,
dovrei zippare un'intera cartella e per farlo ho pensato di usare la libreria SharpZipLib.
Servendomi del tutorial, ho creato una classe che zippasse la cartella voluta, ma quando la eseguo mi viene dato il seguente errore: "Il processo non può accedere al file 'D:\file.zip' perché è in uso da un altro processo."
Come si risolve?
Vi riporto di seguito l'intero codice della classe
Grazie per le eventuali rispostecodice:using System; using System.Collections.Generic; using System.Text; using System.IO; using ICSharpCode.SharpZipLib.Zip; using ICSharpCode.SharpZipLib.Checksums; using System.Threading; namespace MapEditor { static class Pacchetto { public static void CreaZip(string percorso) { DirectoryInfo di = new DirectoryInfo(percorso); ZipOutputStream zip = new ZipOutputStream(File.Create(percorso + "file.zip")); zip.SetLevel(6); // 0 - store only to 9 - means best compression AddFolder2Zip(zip, di, ""); zip.Finish(); zip.Close(); } private static void AddFolder2Zip(ZipOutputStream zip, DirectoryInfo di, string internalzippath) { string izp = internalzippath + di.Name + "/"; // A directory is determined by an entry name with a trailing slash "/" Crc32 crc = new Crc32(); ZipEntry entry = new ZipEntry(izp); entry.Crc = crc.Value; zip.PutNextEntry(entry); foreach (FileInfo fi in di.GetFiles()) AddFile2Zip(zip, fi, izp); foreach (DirectoryInfo sdi in di.GetDirectories()) AddFolder2Zip(zip, sdi, izp); } private static void AddFile2Zip(ZipOutputStream zip, FileInfo fi, string internalzippath) { Crc32 crc = new Crc32(); FileStream fs = File.OpenRead(fi.FullName); byte[] buffer = new byte[fs.Length]; fs.Read(buffer, 0, buffer.Length); ZipEntry entry = new ZipEntry(internalzippath + fi.Name); entry.DateTime = DateTime.Now; entry.Size = fs.Length; fs.Close(); crc.Reset(); crc.Update(buffer); entry.Crc = crc.Value; zip.PutNextEntry(entry); zip.Write(buffer, 0, buffer.Length); } } }![]()

Rispondi quotando
