我有一个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);
}
Run Code Online (Sandbox Code Playgroud)
错误消息是"System.MissingMethodException:Method not found:'System.IO.Compression.ZipArchive System.IO.Compression.ZipFile.OpenRead(System.String)'." 那么我做错了什么或者根本没做什么?
我有一个工具条按钮和两个MDI ChildForms称为C#WinForms应用程序"frmMultiCategoryProject"和"frmTiebreaker".工具条按钮的Click()事件中会发生不同的操作,具体取决于工具条按钮的Text属性.
这是代码:
private void tsbtnAddShowTiebreaker_Click(object sender, EventArgs e)
{
if (tsbtnAddShowTiebreaker.Text == "Add Tiebreaker" || tsbtnAddShowTiebreaker.Text == "Show Tiebreaker")
{
foreach (frmMultiCategoryProject frmamdic in this.MdiChildren)
{
frmamdic.SendToBack();
frmamdic.Hide();
frmamdic.Visible = false;
}
frmTiebreaker frmTB = new frmTiebreaker(Tiebreaker);
frmTB.MdiParent = this;
frmTB.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
frmTB.Dock = DockStyle.Fill;
frmTB.Show();
tsbtnCloseProject.Visible = true;
frmTB.BringToFront();
tsbtnAddShowTiebreaker.Text = "Hide Tiebreaker";
}
else if (tsbtnAddShowTiebreaker.Text == "Hide Tiebreaker")
{
string strMdiChildren = "";
foreach (frmTiebreaker frmTB in this.MdiChildren) // …Run Code Online (Sandbox Code Playgroud)