title: Unzipping a file from Base64 to string using DotNetZip
body: <p>When I am trying to unzip a file in code I get the following error. </p>
  
  <pre><code>   at System.IO.StreamReader..ctor(Stream stream, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize, Boolean leaveOpen)
     at System.IO.StreamReader..ctor(Stream stream)
     at Arkle.AzureServiceBusSample.MessageFetcher.ConvertBase64ZippedStringToNormalString(String stringBase64Zipped) in c:\CodeTfsArklePosBenLenovo\Arkle.AzureServiceBusSample\Arkle.AzureServiceBusSample\MessageFetcher.cs:line 171
     at Arkle.AzureServiceBusSample.MessageFetcher.DownloadMessages(String username, String password, String identifier) in c:\CodeTfsArklePosBenLenovo\Arkle.AzureServiceBusSample\Arkle.AzureServiceBusSample\MessageFetcher.cs:line 92
     at Arkle.AzureServiceBusSample.MessageFetcher.ReceiveMessages(String username, String password, String endPoint, String subscriptionName) in c:\CodeTfsArklePosBenLenovo\Arkle.AzureServiceBusSample\Arkle.AzureServiceBusSample\MessageFetcher.cs:line 48
  </code></pre>
  
  <p>System.ArgumentException: Stream was not readable.
  at System.IO.StreamReader..ctor(Stream stream, Encoding encoding, Boolean
  detectEncodingFromByteOrderMarks, |nt32 bufferSize, Boolean |eaveOpen)
  at System.IO.StreamReader..ctor(Stream stream)</p>
  
  <p>It happens on the line <code>var streamReader1 = new StreamReader(ms);</code> I have checked and just above that I am able to save the file to disk and it is unzipped correctly. However I need to unzip it directly to a memory stream. </p>
  
  <p>I'm using DotNetZip version 1.9.2. </p>
  
  <p>My Code: </p>
  
  <pre><code>    using ionic.zip;
  
      .............
      public static string UnzipToString(string stringBase64Zipped)
      {
          var bytesZipFile = Convert.FromBase64String(stringBase64Zipped);
  
          var msZipFile = new MemoryStream(bytesZipFile);
          msZipFile.Position = 0;
          using (var zipFile1 = ZipFile.Read(msZipFile))
          {
              zipFile1.Save(string.Format(@"C:\Temp\{0}.zip", Guid.NewGuid()));  // This works
              var zipEntry1 = zipFile1.Entries.First();
  
              using (var ms = new MemoryStream())
              {
                  ms.Position = 0;
                  zipEntry1.Extract(ms);
                  var streamReader1 = new StreamReader(ms);
                  var result = String.Empty;
                  ms.Position = 0;
                  result = streamReader1.ReadToEnd();
  
                  return result;
              }
          }
      }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/u8jEg.png" alt="Line and error when it stopz"></p>
  
  <p>I have got a new error now when I try and set the memeorystream position to 0 as per the suggestion below. </p>
  
  <pre><code>System.ObjectDisposedException: Cannot access a closed Stream.
  
     at System.IO.__Error.StreamIsClosed()
  
     at System.IO.MemoryStream.set_Position(Int64 value)
  
     at Arkle.AzureServiceBusSample.MessageFetcher.ConvertBase64ZippedStringToNormalString(String stringBase64Zipped) in c:\CodeTfsArklePosBenLenovo\Arkle.AzureServiceBusSample\Arkle.AzureServiceBusSample\MessageFetcher.cs:line 171
  
     at Arkle.AzureServiceBusSample.MessageFetcher.DownloadMessages(String username, String password, String identifier) in c:\CodeTfsArklePosBenLenovo\Arkle.AzureServiceBusSample\Arkle.AzureServiceBusSample\MessageFetcher.cs:line 92
  
     at Arkle.AzureServiceBusSample.MessageFetcher.ReceiveMessages(String username, String password, String endPoint, String subscriptionName) in c:\CodeTfsArklePosBenLenovo\Arkle.AzureServiceBusSample\Arkle.AzureServiceBusSample\MessageFetcher.cs:line 48
  </code></pre>