简体   繁体   English

如何在c#.net项目中添加Ionic.Zip.dll并使用它从文件夹创建一个zip?

[英]How to add Ionic.Zip.dll in c#.net project and use it to create a zip from folder?

I am new to c#.net using Visual studio 2010 Express. 我是使用Visual Studio 2010 Express的c#.net新手。 I have got an assignment to create a zip file from the folder which contains image files and some text files. 我有一个任务要从包含图像文件和一些文本文件的文件夹中创建一个zip文件。 I have been given Ionic.Zip.dll to use to zip the folder. 我已获得Ionic.Zip.dll用于压缩文件夹。 But i dont know from where to start. 但我不知道从哪里开始。 I have created ac# project and a function that takes a path of folder and returns path of .zip file. 我创建了一个ac#项目和一个函数,该函数采用文件夹路径并返回.zip文件的路径。 I dont know how to add this dll in to my project and how to use it.I have found many code snippets ,but how to start of ... 我不知道如何将这个dll添加到我的项目中以及如何使用它。我找到了很多代码片段,但是如何开始......

Following is the function that i am preparing to make a zip: 以下是我准备制作拉链的功能:

 public static String Zip(String folderPath)
        {
            String zipFilePath = null;
            try
            {


            }
            catch (Exception ex)
            {
                MessageBox.Show("" + ex.Message, "LN Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return zipFilePath;
        }

So please , help to start of . 因此,请帮助开始。 . Thank you in advance . 先感谢您 。 .

To add a reference, right click on your project and select Add Reference 要添加参考,请右键单击您的项目,然后选择添加参考。

在此输入图像描述

Then browse and add the file 然后浏览并添加该文件

在此输入图像描述

Then here is basic code that shows you how to add a file to the zip 然后,这里是基本代码,向您展示如何将文件添加到zip

 using (ZipFile zip = new ZipFile())
 {
     zip.AddFiles(.....);
     zip.Save(....);

 }

Where the dots are in the code sample above, use intellisense and fill out the required parameters. 上面的代码示例中的点处,使用智能感知并填写所需的参数。

We are not here to do your entire assignment for you but this will help get you started. 我们不是为您完成整个任务,但这将有助于您入门。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM