我需要打开XML文件(创建XmlDocument)而不创建本地副本.使用SSH.NET,我想到了以下代码:
var connectionInfo = new ConnectionInfo("host",
"username",
new PasswordAuthenticationMethod("username", "password"));
using (var client = new SftpClient(connectionInfo))
{
client.Connect();
System.IO.MemoryStream mem = new System.IO.MemoryStream();
client.DownloadFile("filename.xml", mem);
mem.Position=0;
using(XmlReader reader = XmlReader.Create(mem))
{
var docc = new XmlDocument();
docc.Load(mem);
}
client.Disconnect();
}
但是卡在docc.Load(mem)上.可能是什么问题呢?
mem对象如下所示:
解决方法:
注意这里:
using(XmlReader reader = XmlReader.Create(mem))
{
var docc = new XmlDocument();
docc.Load(mem);
}
您根本没有使用变量读取器.要么更改为
using(XmlReader reader = XmlReader.Create(mem))
{
var docc = new XmlDocument();
docc.Load(reader);
}
或完全删除阅读器:
docc.Load(mem);