While extracting I see "Cannot Create a file when that file already exists."

Jan 19, 2012 at 10:18 AM


I developed a utility using DotNetZip library. It create a self extractor successfully but it throws error "Cannot Create a file when that file already exists." when it runs to extract files from self extractor file.

Here is the code:


ZipFile zipFile = new ZipFile();
                foreach (string file in files)
                    if (File.Exists(file))
                        zipFile.AddEntry(file, (OpenDelegate)(name => File.Open(file, FileMode.Open, FileAccess.Read)), (CloseDelegate)((name, stream) => stream.Close()));
                SelfExtractorSaveOptions options = new SelfExtractorSaveOptions {
                    DefaultExtractDirectory = this.txtInstalledPath.Text,
                    Flavor = SelfExtractorFlavor.WinFormsApplication,
                    SfxExeWindowTitle = string.Format("Test Patch"),
                    ProductName = "Test",
                    ProductVersion = "",
                    ExtractExistingFile = ExtractExistingFileAction.OverwriteSilently,
                    RemoveUnpackedFilesAfterExecute = true                    
                string exeToGenerate = string.Format(@"patch.exe");
                zipFile.SaveSelfExtractor(exeToGenerate, options);