Blazor(网络组装)新手,所以放轻松:)
我希望能够通过 InputFile 从本地磁盘(大小为 100mb 左右)选择一个 xml 文件并将其加载到 XmlDocument 中,以便我可以查询它。
尝试加载此大小的文件时,它会在 XmlDocument.load() 上崩溃。不确定为什么。
我可以通过 OpenReadStream 加载较小的文件大小,并将 maxAllowedSize 设置为 105000000,但与从 WPF c# 应用程序加载相比,它们需要一个完整的时间。
我不确定是否是流导致速度缓慢,或者我是否在这种大小的 XmlDocument 加载过程中缺少访问本地磁盘文件的一些基本功能?
非常感谢任何帮助。
所以基本上,我想做的就是这样......
<InputFile OnChange="LoadFile">Select file...</InputFile>
@{
private void LoadFile()
{
XmlDocument newXml = new XmlDocument();
newXml.load(ChosenFilePath); //ChosenFilePath or hardcoded path for testing purposes still fails i.e. @"C:\temp\TestFile.xml"
}
}
您需要接受
InputFileChangeEventArgs
并通过它获取您的文件,这相对简单,您的事件处理程序应该是这样的:
private void LoadFile(InputFileChangeEventArgs args)
{
// The argument is to increase the maximum size, by default it only allows
// you to open files less than or equal to 500KiB, the number below is 200MiB
// Alternatively you could pass 'args.File.Size' to allow opening an arbitraily large file
var fileStream = args.File.OpenReadStream(200 * 1024 * 1024);
var newXml = new XmlDocument();
newXml.Load(fileStream);
}
您有没有找到解决方案?我也有同样的问题