Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/326.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# 我的代码不会读取我的XML文件_C#_Xml_Visual Studio 2012 - Fatal编程技术网

C# 我的代码不会读取我的XML文件

C# 我的代码不会读取我的XML文件,c#,xml,visual-studio-2012,C#,Xml,Visual Studio 2012,我用XML保存数据的代码工作得很好。但当我想将其加载到DataGrid时,它找不到该文件 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Window

我用XML保存数据的代码工作得很好。但当我想将其加载到DataGrid时,它找不到该文件

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;

    private void button7_Click(object sender, EventArgs e)
            {
                XmlDataDocument xmldata = new XmlDataDocument();
                xmldata.DataSet.ReadXml(Application.StartupPath + "@leder.xml");

                dataGridView1.DataSource = xmldata.DataSet;
                dataGridView1.DataMember = "Leder";
            }
以下是我的XML注释:

<Bruger>
  <Leder ID="1">
    <Navn>awrea</Navn>
    <Efternavn>aerg</Efternavn>
    <Kva1>arwgllll</Kva1>
  </Leder>    
</Bruger>

将Application.StartupPath+“@leder.xml”放入一个字符串中,显示其内容或简单地调试它


您的文件名是否也包含@

将Application.StartupPath+“@leder.xml”放入一个字符串中,显示其内容或简单地调试它


您的文件名是否也包含@

我很确定你的意思是

xmldata.DataSet.ReadXml(Path.Combine(Application.StartupPath, "leder.xml"));
在调试过程中,当您使用硬编码路径时,
@
可能会卡住


您还需要使用
Path.combined
来确保路径是用适当的
\

构建的,我很确定您的意思

xmldata.DataSet.ReadXml(Path.Combine(Application.StartupPath, "leder.xml"));
在调试过程中,当您使用硬编码路径时,
@
可能会卡住


您还需要使用
路径。组合
以确保使用适当的
\

构建路径,并验证
Application.StartupPath+“@leder.xml”
是否实际指向该文件。可能是您错放了@符号?文件名为@leder.xml吗?请发布Application.StartUpPath的完整路径。同时发布XML文件的完整路径。验证
Application.StartupPath+“@leder.XML”
是否确实指向该文件。可能是您放错了@符号?文件名为@leder.xml吗?请发布Application.StartUpPath的完整路径。同时发布XML文件的完整路径。我的文件名不包含@您建议如何执行该字符串?请添加XML文件的完整路径。我的文件名不包含@您建议如何执行该字符串?请添加XML文件的完整路径。