title: Zipfile in vb.net 4.5 "The directory name is invalid." error - can't identify the cause?
body: <p>I've got a small utility that can encrypt/decrypt using .net 4.5 TripleDES routines. I added compression and found the simpler compression stuff doesn't work for me.</p>
  
  <p>The files referenced in these fields definitely exist, aren't huge at all and are even named in the same case.</p>
  
  <p>Yet I keep getting  "The directory name is invalid.". If I take out the test for existence of the archive, I get a different error - as it's made the zip and it's 0 bytes. I've searched for far longer on this than it took to work out how to use the encryption part of my utility yesterday - and that's with learning how streams work!</p>
  
  <p>Can anyone shed light on this issue at all please?</p>
  
  <pre><code>Private Encoded As String = "C:\TestFile\encoded.txt"
  Private Decoded As String = "C:\TestFile\decoded.txt"
  Private CompressEncoded As String = "C:\TestFile\encoded.zip"
  
  Private Sub Main()
    Compress(Encoded, CompressEncoded)
  End sub
  
  Sub Compress(filename As String, zippedFile As String)
  'Added to handle file already exists error
    If IO.File.Exists(zippedFile) Then IO.File.Delete(zippedFile)
    If IO.File.Exists(filename) Then IO.Compression.ZipFile.CreateFromDirectory(filename, zippedFile, CompressionLevel.Fastest, True)
  End Sub
  </code></pre>
  
  <p>In addition to this code I also tried adding a quick streamreader test to prove to myself that filename does exist. 
  '      Dim sr As New StreamReader(filename)
         MessageBox.Show(sr.ReadToEnd)</p>
  
  <p>It does and displays the line of text within it.</p>
  
  <p>I'd be grateful for any help - this rather silly bug has chewed up lots of time this afternoon that I was hoping to use on something more useful :).</p>
  
  <p>Thanks folks! </p>
  
  <p>Thanks for the answer!</p>
  
  <pre><code>Sub Compress(filename As String, zippedFile As String)
      If IO.File.Exists(zippedFile) Then IO.File.Delete(zippedFile)
  
      If IO.File.Exists(filename) Then
          Using archive As ZipArchive = Open(zippedFile, ZipArchiveMode.Create)
              archive.CreateEntryFromFile(filename, Path.GetFileName(filename), CompressionLevel.Fastest)
          End Using
  
      End If
  End Sub
  
  Sub Decompress(ZippedFile As String, UnzippedFile As String)
      If IO.File.Exists(UnzippedFile) Then IO.File.Delete(UnzippedFile)
  
      If IO.File.Exists(ZippedFile) Then
          Using archive As ZipArchive = Open(ZippedFile, ZipArchiveMode.Read)
              archive.ExtractToDirectory(Path.GetDirectoryName(UnzippedFile))
          End Using
      End If
  End Sub
  </code></pre>