这是我使用 ICSharpCode.SharpZipLib 的一些代码:
public bool Process()
{
var importFile = new FileInfo("c:\\foo\myzip.zip");
var success = true;
using (var zipStream = new ZipInputStream(importFile.OpenRead()))
{
ZipEntry theEntry;
while ((theEntry = zipStream.GetNextEntry()) != null)
{
var lowerName = theEntry.Name.ToLower();
try
{
if (lowerName.EndsWith(".xml") && !lowerName.StartsWith("__macosx"))
{
var doc = new XmlDocument();
doc.Load(zipStream);
}
}
catch (Exception e)
{
success = false;
Log.Error(string.Format("Error parsing {0} ERROR {1}",lowerName,e.Message));
}
}
}
return success;
}
Run Code Online (Sandbox Code Playgroud)
这会处理 zip 中的每个 xml 文件...除了突然出现的愚蠢的 Mac OsX 元文件:)
| 归档时间: |
|
| 查看次数: |
3705 次 |
| 最近记录: |