Jorge Escamilla
Jorge Escamilla

Reputation: 57

Zip new file in VB: File is being used by another procces

Hi folks I'm trying to zip file from a path to another path using ZipArchive and ZipFile but I can't achieve it.

zipped = "C:\Images\zip\file01.ZIP"
file = "C:\Images\file01.BAK"

Using newFile As ZipArchive = ZipFile.Open(zipped, ZipArchiveMode.Create)
                newFile.CreateEntryFromFile(zipped, file, CompressionLevel.Optimal)
End Using

I'm getting the error: "C:\Images\zip\file01.ZIP" File is being used by another proccess

I will appreciate the help

Upvotes: 0

Views: 73

Answers (1)

display name
display name

Reputation: 4185

Try archive mode Update instead of Create for a new entry in a zip archive from an existing file

zipped = "C:\Images\zip\file01.ZIP"
file = "C:\Images\file01.BAK"

Using newFile As ZipArchive = ZipFile.Open(zipped, ZipArchiveMode.Update)
     newFile.CreateEntryFromFile(zipped, file, CompressionLevel.Optimal)
End Using

Upvotes: 1

Related Questions