我有很多压缩文件,现在要读取文件夹里的所有txt文件,然后解压并上传到数据库,请问应该如何做,最好能有点代码参考哈
var zFile = new ZipFile(randomStream) {Password = password };
onRunningPackageLoadTick?.Invoke(0.1F);
var entriesCount = zFile.Count;
for ( var i = 0; i < entriesCount;i++)
{
ZipEntry entry = zFile[i];
onRunningPackageLoadTick?.Invoke(0.1F + i/(float)entriesCount * 0.9F);
if (!entry.IsFile) continue;
var strContentNameOld = entry.Name.Substring(0, entry.Name.LastIndexOf("."));
var strContentNameNew = strContentNameOld.Replace("/", "@").Replace("\\", "@");
using (var entryStream = zFile.GetInputStream(entry))
{
using (var entryMemoryStream = new MemoryStream())
{
entryStream.CopyTo(entryMemoryStream);
entryMemoryStream.Seek(0L, SeekOrigin.Begin);
ContentStreamMap.Add(strContentNameNew, entryMemoryStream);
Load<object>(strContentNameNew);
ContentStreamMap[strContentNameNew] = null;
ContentStreamMap.Remove(strContentNameNew);
}
}
}
// ZipFile.cs
//
// Copyright (C) 2001 Mike Krueger
// Copyright (C) 2004 John Reilly
//
// This file was translated from java, it was part of the GNU Classpath
// Copyright (C) 2001 Free Software Foundation, Inc.
已经解决了