【发布时间】:2020-05-26 22:28:42
【问题描述】:
在 C# 中读取和处理远程压缩 xml 文件的正确方法是什么?
这是我的尝试:
private Task UpdateLegalContractors(string url)
{
url = @"https://srv-file7.gofile.io/download/k67HY4/sampleOpenData.zip";
string res = string.Empty;
using (var file = File.OpenRead(url))
using (var zip = new ZipArchive(file, ZipArchiveMode.Read))
{
foreach (var entry in zip.Entries)
{
using (var stream = entry.Open())
using (var reader = XmlReader.Create(stream))
{
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
res += reader.Name;
break;
case XmlNodeType.XmlDeclaration:
res += "<?xml version=\"1.0\" encoding=\"windows - 1251\"?>";
break;
}
}
}
}
}
var stop = 0;
return null;
}
this 问题中提出了解决方案。
对我来说,一旦到达using (var file = File.OpenRead(url)) 行,解决方案就会出错。错误说明如下:
{"不支持给定路径的格式。"}
我应该改变什么才能使解决方案起作用?
【问题讨论】:
标签: c# xml download stream zip