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?
            Asked
            
        
        
            Active
            
        
            Viewed 480 times
        
    3
            
            
        - 
                    Check 7zip.. great library for file compression. – kevintjuh93 Oct 12 '15 at 07:45
 - 
                    3Please note that there's no such thing as C# 4.5. C# is the *language* and doesn't have any knowledge of `ZipFile` etc - you meant .NET 4.5. – Jon Skeet Oct 12 '15 at 07:55
 - 
                    @JonSkeet thanks for correction. – Imad Oct 12 '15 at 09:33
 
1 Answers
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
 
- 
                    
 - 
                    1@Imad:- It is a class. Check [MSDN](https://msdn.microsoft.com/en-us/library/system.io.compression.ziparchive(v=vs.110).aspx): `Represents a package of compressed files in the zip archive format.` – Rahul Tripathi Oct 12 '15 at 09:33
 - 
                    
 - 
                    @Imad:- That is a seperate question. You can ask it by posting a new question with your attempt. – Rahul Tripathi Oct 12 '15 at 11:52