[英]c# WPF Xdocument load file on a network
我正在使用linq到xml來加載xml文件。 該文件在我的家庭網絡上。
xml文檔的完整路徑:
“ \\\\ FREEBOX \\ Disque dur \\ WpfDatabase \\ Airports.xml”
映射驅動器的路徑:
“X:\\ WpfDatabase \\ Airports.xml”
由於路徑格式錯誤,我無法加載文檔。 我沒有找到任何有效的解決方案
這是加載我的xml文件的錯誤代碼示例:
XDocument dataDoc = XDocument.Load(@"\\X:\\WpfDatabase\Airports.xml");
return from airport in dataDoc.Descendants("Airport")
select new AirportModel
{
Oaci = airport.Attribute("oaci").Value,
Lat = double.Parse(airport.Attribute("lat").Value),
Lon= double.Parse(airport.Attribute("lon").Value)
};
希望您能幫助解決此路徑格式。
等待您的幫助brgds Cyrille
看起來您的路徑字符串格式錯誤。 您在文字前面加上@前綴,這意味着將完全按照所示插入反斜杠。 因此,您將在X:前后加上雙反斜杠。
如果它是映射的驅動器,則格式為@"X:\\WpfDatabase\\Airports.xml"
。 如果使用的是UNC路徑, @"\\\\FREEBOX\\Disque dur\\WpfDatabase\\Airports.xml"
。
如果省略@,則必須轉義反斜杠,因此它將為"X:\\\\WpfDatabase\\\\Airports.xml"
或"\\\\\\\\FREEBOX\\\\Disque dur\\\\WpfDatabase\\\\Airports.xml"
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.