我有一个C# .NET(v4.6.2)WinForms应用程序,我正在访问一个文件,该文件可能是使用“System.IO.Compression;”创建的.zip存档文件,也可能不是。项目中引用了“System.IO.Compression”和“System.IO.Compress.FileSystem”,并在顶部使用了“using System.IO.Compression;”,这是使用NuGet包安装程序安装的。
以下是尝试将文件作为.zip存档文件打开的代码:
错误信息为“System.MissingMethodException: Method not found: 'System.IO.Compression.ZipArchive System.IO.Compression.ZipFile.OpenRead(System.String)'.”,那么我做错了什么或者根本没做呢?
以下是尝试将文件作为.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: Method not found: 'System.IO.Compression.ZipArchive System.IO.Compression.ZipFile.OpenRead(System.String)'.”,那么我做错了什么或者根本没做呢?