title: Append to a file in ZipPackage - .NET
body: <p>I have a zip file that some files are stored in it. I need to append data to one of the files inside it some time after creating and writing into it.</p>
  
  <pre><code>    public void initFileForAppend(string address)
      {
          if (outFile != null)
          {
              flush();
              closeFile();
          }
          workingFile = address;
  
          outFile = (ZipPackage)ZipPackage.Open(workingFile, FileMode.Append);
          getStreamForAppend(OUTPUT_DATA_FILE_NAME);
          getStreamForAppend(OFFSETS_FILE_NAME);
  
      }
  </code></pre>
  
  <p>And this function creates the zip file for the first time:</p>
  
  <pre><code>    public override void initFile(string address)
      {
          if (outFile != null)
          {
              flush();
              closeFile();
          }
          workingFile = address;
  
          outFile = (ZipPackage)ZipPackage.Open(workingFile, FileMode.Create, FileAccess.ReadWrite);
  
          getNewStream(OUTPUT_DATA_FILE_NAME);
          getNewStream(OFFSETS_FILE_NAME, MediaTypeNames.Text.Plain);
          getNewStream(SCENARIO_FILE_NAME, MediaTypeNames.Text.Xml);
      }
  </code></pre>
  
  <p>The <code>ZipPackage.Open...</code> in <code>initFileForAppend</code> throws this exception:</p>
  
  <pre><code>System.ArgumentException was unhandled by user code
    HResult=-2147024809
    Message=Append access can be requested only in write-only mode.
    Source=mscorlib
    StackTrace:
         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, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
         at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync)
         at MS.Internal.IO.Zip.ZipArchive.OpenOnFile(String path, FileMode mode, FileAccess access, FileShare share, Boolean streaming)
         at System.IO.Packaging.ZipPackage..ctor(String path, FileMode mode, FileAccess access, FileShare share, Boolean streaming)
         at System.IO.Packaging.Package.Open(String path, FileMode packageMode, FileAccess packageAccess, FileShare packageShare, Boolean streaming)
         at System.IO.Packaging.Package.Open(String path, FileMode packageMode)
         at SEWS.History.HistoryWriterEngine.initFileForAppend(String address) in e:\Radari\Phase 2\SEWS 2012\trunk\SEWS\History\HistoryWriterEngine.cs:line 46
         at SEWS.MainForm.simulationStartPause() in e:\Radari\Phase 2\SEWS 2012\trunk\SEWS\MainForm.cs:line 539
         at SEWS.MainForm.bgwSimulation_RunWorkerCompleted(Object sender, RunWorkerCompletedEventArgs e) in e:\Radari\Phase 2\SEWS 2012\trunk\SEWS\MainForm.cs:line 1336
         at System.ComponentModel.BackgroundWorker.OnRunWorkerCompleted(RunWorkerCompletedEventArgs e)
         at System.ComponentModel.BackgroundWorker.AsyncOperationCompleted(Object arg)
    InnerException: 
  </code></pre>
  
  <p>I tried using <code>FileAccess.ReadWrite</code> as third argument in <code>ZipPackage.Open...</code> in <code>initFileForAppend</code> but it didn't help.</p>
  
  <p>P.S: I don't want to rewrite the whole code just to use a 3rd party library. I prefer to use <code>ZipPackage</code> in .NET library. </p>