Pergunta

My problem is that I want zip my file into zip formatted file. I used DotNetZib library works fine but there is a little problem in there. I read file from C:\Users\Hüseyin\Desktop\AA for instance. But it creates full path which read from path given above in zip file.I want that when i clicked the zip file a.txt will be directly...Is there anyone to help me?

  using (ZipFile zip=new ZipFile())
        {

            zip.CompressionLevel = Ionic.Zlib.CompressionLevel.Default;
            zip.AddItem(@"C:\Users\Hüseyin\Desktop\AA\a.txt");

            zip.Save(@"C:\Users\Hüseyin\Desktop\AA\deneme.zip");
        }

This code block uses Ionic.Zip; dll and in zip file all path is there i want only a.txt will be in deneme.zip without any directions.Is this more useful to understand.If i wrote wrong sorry, my english is not very good.

Foi útil?

Solução

the ZipFile.AddItem method have another variant with two strings source file path and file path in archive.

You have to use :

        string filepath = @"C:\Users\Hüseyin\Desktop\AA\a.txt";
        zip.AddItem(filePath, Path.GetFileName(filePath));

to put the a.txt file in the root directory of the zip file.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top