Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.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# 在asp.net中使用xdocument更新xml_C#_Asp.net_Xml_Linq To Xml - Fatal编程技术网

C# 在asp.net中使用xdocument更新xml

C# 在asp.net中使用xdocument更新xml,c#,asp.net,xml,linq-to-xml,C#,Asp.net,Xml,Linq To Xml,我正在尝试用XDocument更新一个简单的xml文件。这是我的简单xml文件 <?xml version="1.0" encoding="utf-8" ?> <message>Test test test test</message> 如何更新xml 您需要调用doc.Save(Server.MapPath(“xml/test.xml”)) 在您更改elem值时,它只在内存中。要提交到磁盘,必须保存。将按钮2单击事件处理程序更改为 protecte

我正在尝试用XDocument更新一个简单的xml文件。这是我的简单xml文件

<?xml version="1.0" encoding="utf-8" ?>
<message>Test test test test</message>

如何更新xml

您需要调用
doc.Save(Server.MapPath(“xml/test.xml”))


在您更改
elem
值时,它只在内存中。要提交到磁盘,必须保存。

将按钮2单击事件处理程序更改为

    protected void Button2_Click(object sender, EventArgs e)
    {
        try{
            elem.Value = "test 2 test 2 test 2";
            doc.Save(Server.MapPath("xml/test.xml"));
        }
        catch (Exception ex)
        {
            Label1.Text = ex.Message;
        }
     }

您怎么知道它没有更新xml?我没有看到您在更改值后将值写回页面或保存xml文件。
    protected void Button2_Click(object sender, EventArgs e)
    {
        try{
            elem.Value = "test 2 test 2 test 2";
            doc.Save(Server.MapPath("xml/test.xml"));
        }
        catch (Exception ex)
        {
            Label1.Text = ex.Message;
        }
     }