c# - “ZipArchiveEntry”不包含“ExtractToFile”的定义
问题描述
使用 ASP.NET Framework 4.7.1,我试图压缩一个文件,但 Visual Studio 显示ZipArchiveEntry
不包含ExtractToFile
.
这是我的代码:
[HttpPost]
public ActionResult Index(HttpPostedFileBase file)
{
if (file == null)
return View();
string path = Server.MapPath("~/App_Data/Uploads");
using(ZipArchive archive = new ZipArchive(file.InputStream))
{
foreach(ZipArchiveEntry entry in archive.Entries)
{
if(!string.IsNullOrEmpty(Path.GetExtension(entry.FullName)))
{
entry.ExtractToFile(Path.Combine(path, entry.FullName));
}
else
{
Directory.CreateDirectory(Path.Combine(path, entry.FullName));
}
}
}
}
解决方案
ZipArchive
尽管可以通过引用来添加大部分功能System.IO.Compression
,但要使用该ExtractToFile
选项,您还需要引用System.IO.Compression.FileSystem
.
不需要将其添加为Using
语句,只需引用即可。
推荐阅读
- amazon-web-services - 错误:属性值类型不正确 - Terraform 数据源(aws_ip_ranges)
- mysql - 如何对列求和,并根据 SQL 中的条件将其连接到另一个表?
- package - Julia 1.1.1 迭代器
- python - 如何在 jinja 中查找列表的值索引
- nlp - Spacy NER 推断 GPE 类型
- python - 当一些书有多种类型时,你如何按类型(使用深度学习)对书籍进行分类?
- android - 为什么我的水平滚动不能以编程方式完成?
- go - 当结构在 Go 中包含接口时,新与 {}
- javascript - 修复列之间的空间并在 Highcharts 上对齐标签
- c++ - 如何解释 - 类型 *(& 变量)