title: DotNetZip System.UnauthorizedAccessException: Access to the path is denied
body: <p>I know here is some questions about this error in DotNetZip, I've tried all solutions and failed. I'm developing code on my Win8.1 notebook and have no problems, problems begin after deploy to the remote Win2008R2 server...</p>
  
  <p>Here is the problem method:</p>
  
  <pre><code>public bool CreateZIP(string ListStep)
  {
      Logger logger = LogManager.GetLogger("Task:CreateZIP" + this.TaskGuid);
  
      using (ZipFile zip = new ZipFile())
      {
          zip.AlternateEncoding = System.Text.Encoding.GetEncoding("cp866");
          zip.AlternateEncodingUsage = Ionic.Zip.ZipOption.Always;
  
          ...
          zip.AddFile(...) loop
          ...
  
          zip.MaxOutputSegmentSize = Properties.Settings.Default.ZIPSizeLimit * 1024 * 1024;
  
          string zipFolder = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"zip-tmp");
          string TaskZipFolder = Path.Combine(zipFolder, this.TaskGuid);
  
          try
          {
              if (!Directory.Exists(zipFolder)) Directory.CreateDirectory(zipFolder);
              if (!Directory.Exists(TaskZipFolder)) Directory.CreateDirectory(TaskZipFolder);
  
              zip.TempFileFolder = Path.GetTempPath();
              zip.Save(Path.Combine(TaskZipFolder, this.TaskGuid + @".zip"));
          }
          catch (Exception e)
          {
              logger.Fatal("Unable to save ZIP into ({0}): {1}", Path.Combine(TaskZipFolder, this.TaskGuid + @".zip"), e.ToString());
              throw;
          }
      }
      return true;
  }
  </code></pre>
  
  <p>This code is running on remote server from domain user <code>gfo-svc</code> from <code>C:\Courier\WD</code> directory.
  Each object instance has it's GUID, for example <code>e1664582-1bbc-4a9f-a9fe-e7ce4a0a8a55</code>
  So the <code>zipFolder</code> variable value is <code>C:\Courier\WD\zip-tmp</code> and <code>TaskZipFolder</code> value is <code>C:\Courier\WD\zip-tmp\e1664582-1bbc-4a9f-a9fe-e7ce4a0a8a55</code></p>
  
  <p>When this code tries to run it fails with this stack trace:</p>
  
  <pre><code>Unable to save ZIP into (C:\Courier\WD\zip-tmp\e1664582-1bbc-4a9f-a9fe-e7ce4a0a8a55\e1664582-1bbc-4a9f-a9fe-e7ce4a0a8a55.zip): System.UnauthorizedAccessException: Access to the path is denied.
     at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
     at System.IO.__Error.WinIOError()
     at System.IO.File.InternalMove(String sourceFileName, String destFileName, Boolean checkHost)
     at Ionic.Zip.ZipSegmentedStream.TruncateBackward(UInt32 diskNumber, Int64 offset)
     at Ionic.Zip.ZipEntry.Write(Stream s)
     at Ionic.Zip.ZipFile.Save()
     at Ionic.Zip.ZipFile.Save(String fileName)
     at Worker.Task.CreateZIP(String ListStep) in Worker.cs:line 844
  </code></pre>
  
  <p>Line 844 contains this code: <code>zip.Save(Path.Combine(TaskZipFolder, this.TaskGuid + @".zip"));</code></p>
  
  <p>But in the <code>C:\Courier\WD\zip-tmp\e1664582-1bbc-4a9f-a9fe-e7ce4a0a8a55</code> folder I can see file <code>e1664582-1bbc-4a9f-a9fe-e7ce4a0a8a55.z01</code>, so the first part of archive was saved before failure.</p>
  
  <p><code>gfo-svc</code> user has ownership on <code>C:\Courier\WD</code> directory and my code could create <code>zip-tmp</code> directory if it is not exists, and GUID-named directory in it. So the problem is not in Windows Security permissions.
  UAC on this remote server is disabled.</p>
  
  <p>What could I do wrong? What might be wrong with my environment? What could I do?</p>