Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Windows 8存储文件_C#_File_Windows 8 - Fatal编程技术网

C# Windows 8存储文件

C# Windows 8存储文件,c#,file,windows-8,C#,File,Windows 8,我有以下代码 StorageFile sf = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync("/data/elements.xml"); 我正在尝试从项目中的数据文件夹加载elements.xml文件。我得到以下错误: “”值不在预期范围内。“” 我试着反转斜杠并在字符串前添加@。运气不好。很抱歉,如果要使用路径,请使用反斜杠。如果elements.xml位于数据文件夹中,并且包含下

我有以下代码

StorageFile sf = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync("/data/elements.xml");
我正在尝试从项目中的数据文件夹加载elements.xml文件。我得到以下错误:

“”值不在预期范围内。“”


我试着反转斜杠并在字符串前添加@。运气不好。

很抱歉,如果要使用路径,请使用反斜杠。

如果
elements.xml
位于数据文件夹中,并且包含下面代码段的类文件位于另一个文件夹(如DataModel)中,请使用如图所示的字符串

var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync("Data\\\elements.xml");

为什么要使用前导斜杠?这将创建一条绝对路径,而不是相对路径。另外,将斜杠改为反斜杠。