Cannot save a simple zip file

Feb 10, 2010 at 5:43 PM

Hi,

 

I'm building a very simple program to compress several files inside a folder.

I'm having troubles saving the output file, all folders permissions are OK there's nothing acessing the outup file, it gives me an error acessing the output file :S


C:\Documents and Settings\xnbs190\My Documents\Visual Studio 2008\Projects\moveInteractionsMSG\moveInteractionsMSG\bi
n\Release>moveInteractionsMSG.exe
D:\teste_temp_msg\1-1H1Z8FQ.msg
D:\teste_temp_msg\1-1H2AIFF.msg
D:\teste_temp_msg\1-1H2RJ9A.msg
D:\teste_temp_msg\1-1H2RJM2.msg
D:\teste_temp_msg\1-1I9MZQ0.msg
D:\teste_temp_msg\1-1I9MZQA.msg
6

Unhandled Exception: System.IO.IOException: The process cannot access the file 'D:\archivemsg\msg_archive.zip' becaus
e it is being used by another process.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.File.Delete(String path)
   at Ionic.Zip.ZipFile.Save()
   at Ionic.Zip.ZipFile.Save(String fileName)
   at ConsoleApplication1.Program.Main(String[] args) in C:\Documents and Settings\xnbs190\My Documents\Visual Studio
 2008\Projects\moveInteractionsMSG\moveInteractionsMSG\Program.cs:line 60

 

The code is very simple:

            FileStream destFile = File.Create(output_zip_file);
            FileInfo[] files_to_compress = getDirectoryFiles(new DirectoryInfo(tmp_msg_dir));


            using (Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile())
            {
                foreach (FileInfo fi in files_to_compress)
                {
                    Console.WriteLine(tmp_msg_dir + "\\" + fi.ToString());
                    zip.AddFile(tmp_msg_dir + "\\" + fi.ToString(), dia_pasta);
                }
                
                Console.WriteLine(zip.Count);
                zip.Save(output_zip_file);
                
            }

 

 

Thanks in advance for any help.

 

Feb 10, 2010 at 5:55 PM

it's official.. i'm a dumbass.

I was creating a FileStream for the outputfile and was saving the zip at the same time.

FileStream destFile = File.Create(output_zip_file); -> whas causing the problem

 

Coordinator
Feb 10, 2010 at 9:29 PM

Glad you sorted it. Don't be too hard on yourself, We've all had those days.