Error: Unable to move the replacement file to the file to be replaced. The file to be replaced has retained its original name.

Feb 29, 2008 at 5:22 PM
Hi! i'm a new user of this great library, now I've found when you create a physical zip file (Test.zip), and you re-use this file to add more contents, some explanation(please note this as basic just to show...):

Private Sub AddCollFiles(DirStruc as Collection)
Dim ZipUtil As New ZipFile(ZipFileName)
For iPos = 0 To DirStruc.Files.Count - 1
ZipUtil.AddItem(DirStruc.Files.Item(iPos).Path, DirStruc.Files.Item(iPos).ParentDir)
Next
ZipUtil.Save()
end Sub

Sub Main()
Dim a as Collection=GetContents(A)
Dim b as Collection=GetContents(A)

AddCollFiles(a)
AddCollFiles(b)
End Sub

You get:
System.IO.IOException: Unable to move the replacement file to the file to be replaced. The file to be replaced has retained its original name.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.__Error.WinIOError()
at System.IO.File.Replace(String sourceFileName, String destinationFileName, String destinationBackupFileName, Boolean ignoreMetadataErrors)
at System.IO.File.Replace(String sourceFileName, String destinationFileName, String destinationBackupFileName)
at Ionic.Utils.Zip.ZipFile.Save()

The solution is to set the ZipUtil.TempFileFolder property, cheers.