I have a problem which probably is very easy to solve, but I just don't find a solution.
In my application a user is importing .csv-files into a database. After the import the .csv-file is being zipped and afterwards deletes from the directory on the filesystem. That works perfectly well.
However, the user ought to get the possibility to unzip a specific file again. That works, too. But when I want to delete this file from the zip-archive and save this zip-archive, I always get the error 57, sayint that the process cannot access the file as another process is using it.
This is my code and any help is appreciated:
Public Shared Sub ExtractOneFile(strZip As String, strFile As String, strDestination As String)
'strZip = Ziparchive
'strFile = das zu entpackende .csv-File
'strDestination = Zielverzeichnis
Try
Using zip As ZipFile = ZipFile.Read(strZip)
Dim e As ZipEntry
For Each e In zip
If e.FileName = strFile Then
e.Extract(strDestination, ExtractExistingFileAction.OverwriteSilently)
zip.RemoveEntry(e)
zip.Save()
Exit For
End IfNext
End Using
Catch
MsgBox("Zip-Class; ExtractOneFile" & vbCrLf & Err.ToString)
End Try
End Sub