I want to extract archive. But the problem is, when the code runs, it throws the exception below:
System.IO.IOException: 'The file 'filename' already exists.'
Here are the code
File.WriteAllBytes(String_TempDir & "\rzip.zip", My.Resources.Resszip) 'I wrote the file from my application resources
Compression.ZipFile.ExtractToDirectory(String_TempDir & "\rzip.zip", String_TempDir) 'This line throws the exception
File.Delete(String_TempDir & "\rzip.zip")
I saw nothing(no file) before that code executed...
After the code executed, It throws the exception, but, my archived file has been extracted.
I used Try statement to distinguish the exception but it's still throwing that exception...
Try
Compression.ZipFile.ExtractToDirectory(String_TempDir & "\rzip.zip", String_TempDir)
Catch ex As IOException
'That's it.
End Try
The String_TempDir is a string which I assign it with:
'global declaration:
Dim folder As String = Path.Combine(Path.GetTempPath, Path.GetRandomFileName)
'End of global declaration
Public Function GetTempDir() As String
Do While Directory.Exists(folder) Or File.Exists(folder)
folder = Path.Combine(Path.GetTempPath, Path.GetRandomFileName)
Loop
Return folder
End Function
'Form loads
Directory.CreateDirectory(folder)
String_TempDir = folder