[英]Blazor c# - how to XmlDocument.load() a local file
Blazor(網絡組裝)的新手,所以 go 很簡單:)
我希望能夠通過 InputFile 從本地磁盤(大小在 100mb 左右)獲取 select 和 xml 文件,並將其加載到 XmlDocument 中,以便我可以查詢它。
在嘗試加載這種大小的文件時,它會在 XmlDocument.load() 上崩潰。 不確定為什么。
我可以讓它通過 OpenReadStream 加載較小的文件大小並將 maxAllowedSize 設置為 105000000,但與說從 WPF c# 應用程序加載它相比,它們需要一個完整的年齡。
我不確定 stream 是否導致速度緩慢,或者我是否在這種大小的 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);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.