1

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.

McMillan Cheng
  • 382
  • 1
  • 6
  • 20
husonos
  • 241
  • 3
  • 14

1 Answers1

4

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.

Renaud Bancel
  • 853
  • 6
  • 5
  • Thanks for your help.Works fine question is over.That is what i want o write in the code...A little correction has to be made in zip.AddItem function not filePath must be filepath i guess – husonos Jan 31 '14 at 13:36