在.NET 4.5正在压缩文件 [英] Zipping files in .NET 4.5
本文介绍了在.NET 4.5正在压缩文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要使用.NET 4.5提供了邮编
功能。我有 ZipFile.CreateFromDirectory
,它有3个重载。所有这些需求sourceDirectoryName并没有直接的文件名。我想只有压缩单个文件不是整个文件夹。将其放入文件夹是唯一的选择?为什么我不能压缩它没有呢?
I want to using Zip
feature that .NET 4.5 has provided. I have got ZipFile.CreateFromDirectory
and it has 3 overloads. All of those demands sourceDirectoryName and not filename directly. I want to zip only single file not entire folder. Putting it into folder is only option? Why can't I zip it without that?
推荐答案
试试这个:
using (FileStream fs = new FileStream(@"C:\Temp\myZip.zip",FileMode.Create))
using (ZipArchive za = new ZipArchive(fs, ZipArchiveMode.Create))
{
za.CreateEntryFromFile(@"C:\Temp\myFile.txt", "myFile.txt");
}
这篇关于在.NET 4.5正在压缩文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文