我正在使用SharpCompress库创建我的zip存档。我成功创建了Zip存档,但是,库,自动更新文件的编辑日期到当前日期时间。我不想要这种行为。我的意思是:编辑日期将保持不变(即:存档中文件的编辑日期与存档前的文件相同)。
如何避免这种行为?这是我的代码:
private String CreaPacchettoZip(String idProcesso, String pdfBasePath)
{
List<String> listaPdfDiProcesso = FileHelper.EstraiListaPdfDaDirecotry(pdfBasePath);
String zipFile = Path.Combine(pdfBasePath, idProcesso + ".zip");
using (var archive = ZipArchive.Create())
{
foreach (String file in listaPdfDiProcesso)
{
archive.AddEntry(file, new FileInfo(pdfBasePath, file));
}
using (Stream newStream = File.Create(zipFile))
{
archive.SaveTo(newStream, SharpCompress.Common.CompressionType.None);
}
}
return zipFile;
}
答案 0 :(得分:0)
在这里的某个地方
foreach (String file in listaPdfDiProcesso)
{ var fileInfo = new FileInfo(pdfBasePath, file);
// If here date is ~DateTime.Now read it some other way like File.Open from file and then set it to fileInfo if it has Setter or Date setting method
var originalFileCreationDate = e.DateItGotCreated; //DateItGotCreated is not actual propety or method.
archive.AddEntry(file, fileInfo);
}