【发布时间】:2021-04-28 00:59:43
【问题描述】:
所以我找到了很多关于这方面的信息,而且有很多不同的方式,这似乎非常令人不知所措,因为我还是新手。所以我的问题是,我如何将此功能合并到我自己的代码中,以便在提取文件时自动覆盖文件而不是给我一个错误?如果不是这样,有人可以将我引向易于理解和教我的教学领域吗?
以下是我当前保存和从内存中提取文件夹的代码。
public static void Extract(string nameSpace, string outDirectory, string internalFilePath, string resourceName)
{
Assembly assembly = Assembly.GetCallingAssembly();
using (Stream s = assembly.GetManifestResourceStream(nameSpace + "." + (internalFilePath == "" ? "" : internalFilePath + ".") + resourceName))
using (BinaryReader r = new BinaryReader(s))
using (FileStream fs = new FileStream(outDirectory + "//" + resourceName, FileMode.OpenOrCreate))
using (BinaryWriter w = new BinaryWriter(fs))
w.Write(r.ReadBytes((int)s.Length));
}
这就是我目前正在开展业务的地方。
private void button2_Click(object sender, EventArgs e)
{
Extract("nameSpace", @"outDirectory", "internalFilePath", "resourceName");
string sourceZipFile = @"C:\test.zip";
string targetFolder = @"C:\";
ZipFile.ExtractToDirectory(sourceZipFile, targetFolder);
Process process = new Process();
ProcessStartInfo p= new ProcessStartInfo();
p.FileName = @"C:\test.zip";
if ((System.IO.File.Exists(p.FileName)))
{
System.IO.File.Delete(p.FileName);
}
}
【问题讨论】: