单击事件以更新文件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");