문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top