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,421,763
  • 867
  • 9,128
  • 9,194
Imad
  • 7,126
  • 12
  • 55
  • 112

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
  • 168,305
  • 31
  • 280
  • 331