DotnetZip zip file without directory folders

3

I'm using dotnetzip to zip a file but the zip file takes the root directory of the file, I just wanted to zip the file without the directories:

    public static void Zipar(FileInfo file)
    {
        using (ZipFile zip = new ZipFile())
        {
            zip.Password = "******";
            zip.AddFile(file.FullName);

            zip.Save(file.FullName.Replace(file.Extension,".zip"));
        }
    }

Inside the zip file looks like this: \pasta\pasta\arquivo.txt

I wanted it to look like this: arquivo.txt

    
asked by anonymous 09.11.2017 / 13:15

1 answer

3

Simply enter a second parameter in the AddFile method, see:

public static void Zipar(FileInfo file)
{
    using (ZipFile zip = new ZipFile())
    {
        zip.Password = "******";
        zip.AddFile(file.FullName,""); //Aqui, se não informar o diretório ele vai ficar na raiz do arquivo

        zip.Save(file.FullName.Replace(file.Extension,".zip"));
    }
}
    
09.11.2017 / 13:17