C# 使用C编辑Xml文件#
这是我的xml文件 -->C# 使用C编辑Xml文件#,c#,C#,这是我的xml文件 --> 我需要按c#编辑我的DailyFilName。使用键我需要更改值。根据文件类型,您可以使用许多选项 如果它是标准XML文件,则可以使用内置的.NET类,如、和。示例可在MSDN上找到 如果是app.config文件,则可以使用配置命名空间直接处理该文件,而无需手动读/写Xml。查看MSDN上的类以获取一些示例。根据文件的类型,您可以使用许多选项 如果它是标准XML文件,则可以使用内置的.NET类,如、和。示例可在MSDN上找到 如果是app.conf
我需要按c#编辑我的DailyFilName。使用键我需要更改值。根据文件类型,您可以使用许多选项 如果它是标准XML文件,则可以使用内置的.NET类,如、和。示例可在MSDN上找到
如果是app.config文件,则可以使用配置命名空间直接处理该文件,而无需手动读/写Xml。查看MSDN上的类以获取一些示例。根据文件的类型,您可以使用许多选项 如果它是标准XML文件,则可以使用内置的.NET类,如、和。示例可在MSDN上找到
如果是app.config文件,则可以使用配置命名空间直接处理该文件,而无需手动读/写Xml。查看MSDN上的类以获取一些示例。[注意:如果您试图操作app.config或web.config文件中的appSettings部分,建议使用。] 您可以这样做:
private void SetValue(String key, String value)
{
XDocument doc = XDocument.Load("...");
XElement element = doc.Descendants("add").Where(d => d.Attribute("key") != null && d.Attribute("key").Value == key).First();
element.Attribute("value").Value = value;
}
用法
[注意:如果您试图操作app.config或web.config文件中的appSettings部分,建议使用。] 您可以这样做:
private void SetValue(String key, String value)
{
XDocument doc = XDocument.Load("...");
XElement element = doc.Descendants("add").Where(d => d.Attribute("key") != null && d.Attribute("key").Value == key).First();
element.Attribute("value").Value = value;
}
用法
如果您正在使用app.config文件,我想您需要这个
ExeConfigurationFileMap map = new ExeConfigurationFileMap { ExeConfigFilename = "C:\\App.config"};
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
config.AppSettings.Settings["SettingKey1"].Value = "newValue";
config.Save();
如果您正在使用app.config文件,我想您需要这个
ExeConfigurationFileMap map = new ExeConfigurationFileMap { ExeConfigFilename = "C:\\App.config"};
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
config.AppSettings.Settings["SettingKey1"].Value = "newValue";
config.Save();
这是App.config文件吗?这是App.config文件吗?
ExeConfigurationFileMap map = new ExeConfigurationFileMap { ExeConfigFilename = "C:\\App.config"};
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
config.AppSettings.Settings["SettingKey1"].Value = "newValue";
config.Save();