Create normal zip file programmatically

后端 未结 11 887
野的像风
野的像风 2020-12-05 00:06

I have seen many tutorials on how to compress a single file in c#. But I need to be able to create a normal *.zip file out of more than just one file. Is there anything in .

11条回答
  •  鱼传尺愫
    2020-12-05 00:23

    This can be done with just one line of code using just Dot Net. Below is sample code copied from MSDN

    Step 1: Add a reference to System.IO.Compression.FileSystem

    Step 2: Follow the code below

            static void Main(string[] args)
            {
                string startPath = @"c:\example\start";
                string zipPath = @"c:\example\result.zip";
                string extractPath = @"c:\example\extract";
    
                ZipFile.CreateFromDirectory(startPath, zipPath);
    
                ZipFile.ExtractToDirectory(zipPath, extractPath);
            }
    

提交回复
热议问题