c# - Using ZipFile compression: An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll -
i'm unsure why exception happening after folder contents zipped. should right?
error: unhandled exception of type 'system.io.ioexception' occurred in mscorlib.dll additional information: process cannot access file 'c:\temp\pack.zip' because being used process.
private static string directorypath = @"c:\temp\"; static void main(string[] args) { zipfolder(directorypath, directorypath+@"pack.zip"); } public static void zipfolder(string targetpath, string resultpath) { zipfile.createfromdirectory(targetpath, resultpath,compressionlevel.optimal,true); }
what doing in code reading content of c:\temp while trying create zip file in same directory.
instead create file in app directory , copy file temp folder later on.
var newfilepath = path.combine(directorypath, "pack.zip"); if(file.exists(newfilepath))file.delete(newfilepath); //remove file if exists if (file.exists("pack.zip")) file.delete("pack.zip"); //remove file if exists zipfolder(directorypath, "pack.zip"); file.move("pack.zip", newfilepath);
Comments
Post a Comment