为了账号安全,请及时绑定邮箱和手机立即绑定

修改配置文件的问题

修改配置文件的问题

九州编程 2018-12-06 12:47:37
1:我在app.config文件里自定义了一个section <section name="Notify" type="Roboth.NotifySection,Roboth"/> <Notify>     <OrderStateTypes>    </OrderStateTypes> </Notify> 2:我想通过程序向OrderStateTypes添加<add id="1" status="2" ispaid="1" isdeleted="0" statusnotify="payment at full"></add> 3:code Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);            NotifySection section = (NotifySection)config.GetSection("Notify");            //string xmlfile = section.MsgTypes["OrderStateChanged"].Parameters["OrderStateTypeXmlPath"].ParamValue.ToString();            OrderStateTypeElement ost = new OrderStateTypeElement();            ost.IsDeleted = 1;            ost.IsPaid = 1;            ost.Status = 1;            ost.Name = "1";            ost.StatusNotify = "jj";            section.OrderStateTypes.Add(ost);            config.Save(); 我该如何实现 呢? 请大家指教
查看完整描述

3 回答

?
慕村225694

TA贡献1880条经验 获得超4个赞

XmlDocument doc = new XmlDocument(); doc.Load(configFilePath); XmlNode sectionNode = doc.SelectSingleNode("Notify/OrderStateTypes"); XmlNode newNode = doc.CreateElement("add"); XmlAttribute attId = doc.CreateAttribute("id"); attId.Value = youId; newNode.Attributes.Append(attId); ...append other attributes sectionNode.AppendChild(newNode); doc.Save(configFilePath);
查看完整回答
反对 回复 2019-01-21
  • 3 回答
  • 0 关注
  • 410 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信