Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/291.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#_C#_Winforms - Fatal编程技术网

单击事件以更新文件C#

单击事件以更新文件C#,c#,winforms,C#,Winforms,我正在尝试创建一个更新配置文件的应用程序 本人已填妥以下表格: 我还创建了以下代码: using System; using System.IO; using System.Windows.Forms; namespace DebugOnOrOff { public partial class Form1 : Form { public Form1() { InitializeComponent(); } priva

我正在尝试创建一个更新配置文件的应用程序

本人已填妥以下表格:

我还创建了以下代码:

using System;
using System.IO;
using System.Windows.Forms;

namespace DebugOnOrOff
{
public partial class Form1 : Form
{
    public Form1()
    {
                    InitializeComponent();

    }

    private void button1_Click(object sender, EventArgs e)
    {
        string text = File.ReadAllText("C:\\Users\\User\\Desktop\\app.config");
        text = text.Replace("DebugOff", "DebugOn");
        File.WriteAllText("app.config", text);

    }
}
}
File.WriteAllText(“app.config”,text)

应该是:

File.WriteAllText(“C:\\Users\\User\\Desktop\\app.config”,text)

应该是

File.WriteAllText("C:\\Users\\User\\Desktop\\app.config", text);

作为旁注,您也可以替换此

File.ReadAllText("C:\\Users\\User\\Desktop\\app.config");


问题是,你做错了,有特定的方法来更新应用程序设置。请参阅问题的第一个答案。技术正确时,有更好的方法可以对应用程序设置进行udating。技术正确时,有更好的方法可以对应用程序设置进行udating。
File.WriteAllText(@"C:\Users\User\Desktop\app.config", text);
File.ReadAllText("C:\\Users\\User\\Desktop\\app.config");
File.ReadAllText(@"C:\Users\User\Desktop\app.config");