【发布时间】:2017-06-01 23:53:13
【问题描述】:
我有一个 C# .NET (v4.6.2) WinForms 应用程序,我正在访问一个可能/可能不是使用“System.IO.Compression;”创建的 .zip 存档的文件。我在项目中有“System.IO.Compression”和“System.IO.Compress.FileSystem”引用,顶部有“使用 System.IO.Compression;”,它是使用 NuGet 包安装程序安装的。
以下是尝试将文件作为 .zip 存档打开的代码:
try
{
string extractPath = Path.GetTempFileName();
string strGameVersion = "";
string strProjectType = "";
using (ZipArchive archive = ZipFile.OpenRead(OpenFilePath))
{
FileStream fs = new FileStream(extractPath, FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs);
foreach (ZipArchiveEntry entry in archive.Entries)
{
if (entry.FullName.Contains("ProjectData.txt"))
{
entry.ExtractToFile(Path.Combine(extractPath, entry.FullName));
strGameVersion = sr.ReadLine();
strProjectType = sr.ReadLine();
}
File.Delete(extractPath);
}
sr.Close();
fs.Close();
archive.Dispose();
}
}
catch(System.IO.FileFormatException flex1)
{
MessageBox.Show(flex1.ToString(), "oops.", MessageBoxButtons.OK, MessageBox.Icon.Error);
}
错误消息是“System.MissingMethodException:找不到方法:'System.IO.Compression.ZipArchive System.IO.Compression.ZipFile.OpenRead(System.String)'。” 那么我做错了什么或根本没有做什么?
【问题讨论】:
标签: c# .net winforms ziparchive