Here is my code that I use to extract the zip file, making sure there are no dirty files in the destination directory.
internal void UnzipProject()
{
if (Directory.Exists(SourceDir))
Directory.Delete(SourceDir, true);
if (File.Exists(CodeZipFile))
{
Directory.CreateDirectory(SourceDir);
ZipFile.ExtractToDirectory(CodeZipFile, SourceDir);
}
}
Once it was Directory.CreateDirectory(SourceDir)not possible to create a new dir, and I get an exception in the next line, but if I backtrack and try to create a dir again, it will work. Exactly the same pattern is repeated on the next run.
EDIT
Here is an exception that is actually related to the fact that dir was not created, I see that src dir does not exist:
System.UnauthorizedAccessException was unhandled
HResult=-2147024891
Message=Access to the path '(...MyPath...)\src\MySolution.sln' is denied.
Source=mscorlib
StackTrace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at System.IO.Compression.ZipFileExtensions.ExtractToFile(ZipArchiveEntry source, String destinationFileName, Boolean overwrite)
at System.IO.Compression.ZipFileExtensions.ExtractToDirectory(ZipArchive source, String destinationDirectoryName)
at System.IO.Compression.ZipFile.ExtractToDirectory(String sourceArchiveFileName, String destinationDirectoryName, Encoding entryNameEncoding)
at System.IO.Compression.ZipFile.ExtractToDirectory(String sourceArchiveFileName, String destinationDirectoryName)
........