【发布时间】:2015-06-23 07:54:56
【问题描述】:
我正在尝试使用 pack://application 加载文件:该文件位于我的项目的根目录中,但我不断收到空引用错误。但是,当我进行绝对引用时,它会找到文件并加载得很好。 我在这里错过了什么?
这行不通
var txt = Application.GetContentStream(new Uri(@"pack://application:,,,/Layout.xml"));
string full = new StreamReader(txt.Stream).ReadToEnd();
或 Pack://Application,,,/ 的任何变体
这行得通,但我不想使用它,无论如何似乎都是不好的做法
var path = AppDomain.CurrentDomain.BaseDirectory.Substring(0, (AppDomain.CurrentDomain.BaseDirectory.Length - 10));
var txt = path + @"Layout.xml";
string full = new StreamReader(txt).ReadToEnd();
【问题讨论】:
-
欢迎来到 Stackoverflow!
标签: c# xml wpf visual-studio relative-path