![](/img/trans.png)
[英]Can i create zip file (uncompressed) programatically in c# without using any library (without .net zip classes)
[英]I want zip file without any directories in zip file.How can I do in c#
我的问题是我想将我的文件压缩成zip格式的文件。 我使用DotNetZib库工作正常,但那里有一点问题。 我从C:\\ Users \\Hüseyin\\ Desktop \\ AA中读取文件。 但它创建了完整的路径,从zip文件中的上面给出的路径读取。我希望当我点击zip文件a.txt将直接...有没有人帮助我?
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");
}
这个代码块使用Ionic.Zip; dll和zip文件中的所有路径都在那里我想要只有a.txt将在deneme.zip中没有任何指示。这对于理解更有用。如果我写错了抱歉,我的英语不是很好。
ZipFile.AddItem方法有另一个变体,在归档中有两个字符串源文件路径和文件路径。
你必须使用:
string filepath = @"C:\Users\Hüseyin\Desktop\AA\a.txt";
zip.AddItem(filePath, Path.GetFileName(filePath));
将a.txt文件放在zip文件的根目录中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.