3

I want to using Zip feature that .NET 4.5 has provided. I have got ZipFile.CreateFromDirectory and it has 3 overloads. All of those demands sourceDirectoryName and not filename directly. I want to zip only single file not entire folder. Putting it into folder is only option? Why can't I zip it without that?

Jon Skeet
  • 1,335,956
  • 823
  • 8,931
  • 9,049
Imad
  • 6,736
  • 10
  • 49
  • 101

1 Answers1

3

Try this:

using (FileStream fs = new FileStream(@"C:\Temp\myZip.zip",FileMode.Create))
using (ZipArchive za = new ZipArchive(fs, ZipArchiveMode.Create))
{
    za.CreateEntryFromFile(@"C:\Temp\myFile.txt", "myFile.txt");
}
Rahul Tripathi
  • 161,154
  • 30
  • 262
  • 319