当前位置: 首页 > news >正文

网站什么时候备案产品推广怎么做

网站什么时候备案,产品推广怎么做,建工网校一建,哈尔滨中国建设银行网站首页有时候一些用户的配置需要写入在本地,不能每次程序启动都让用户重新设置一下吧。 下面先说基本用法: 1、创建winform项目之后自动会生成App.config文件,如果默认没有,就对项目右键-新建项-APP配置文件 这个文件创建后自动就有的&#xff0…

有时候一些用户的配置需要写入在本地,不能每次程序启动都让用户重新设置一下吧。

下面先说基本用法:

1、创建winform项目之后自动会生成App.config文件,如果默认没有,就对项目右键-新建项-APP配置文件

这个文件创建后自动就有的,如果没有就新建一个,我们可以往里面添加需要的数据:

<?xml version="1.0" encoding="utf-8" ?>
<configuration><appSettings><add key="key1" value="hello"/><add key="key2" value="world!"/></appSettings>
</configuration>
里面的appSettings节点和子节点就是我添加上去的

2、读写

项目的引用增加System.Configuration,然后在cs文件引入System.Configuration

然后这样就可以读到数据了:

string key1 = ConfigurationManager.AppSettings["key1"];Debug.WriteLine("key1=" + key1);

 

这样修改数据:

ConfigurationManager.AppSettings.Set("key1","new hello!");Debug.WriteLine("new-key1=" + ConfigurationManager.AppSettings["key1"]);

一切看起来都非常简单,没有什么问题,打印出来显示都是正确的。

实际上他设置的时候并没有真正写入xml,而是修改了内存中的值而已!

 

3、正确的做法应该是按照对待一个普通的xml来进行读写操作,代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Xml;namespace TestConfig
{class ConfigSettings{private ConfigSettings() { }public static string ReadSetting(string key) {//不建议通过这种自带的方式进行读取;如果手动修改了配置文件,则不会第二次读取的时候,依旧是内存中的值。可以通过XML方式进行读取。//return ConfigurationSettings.AppSettings[key];XmlDocument doc = loadConfigDocument();XmlNode node = doc.SelectSingleNode("//appSettings");if (node == null) throw new InvalidOperationException("appSettings section not found in config file.");try{XmlElement elem = (XmlElement)node.SelectSingleNode(string.Format("//add[@key='{0}']", key));if (elem != null) {return elem.GetAttribute("value");}}catch {throw;}return "";}public static void WriteSetting(string key, string value) {XmlDocument doc = loadConfigDocument();XmlNode node = doc.SelectSingleNode("//appSettings");if (node == null)throw new InvalidOperationException("appSettings section not found in config file.");try{XmlElement elem = (XmlElement)node.SelectSingleNode(string.Format("//add[@key='{0}']", key));if (elem != null){elem.SetAttribute("value", value);}else{elem = doc.CreateElement("add");elem.SetAttribute("key", key);elem.SetAttribute("value", value);node.AppendChild(elem);}doc.Save(getConfigFilePath());}catch {throw;}}public static void RemoveSetting(string key) {XmlDocument doc = loadConfigDocument();XmlNode node = doc.SelectSingleNode("//appSettings");try{if (node == null)throw new InvalidOperationException("appSettings section not found in config file.");else{node.RemoveChild(node.SelectSingleNode(string.Format("//add[@key='{0}']", key)));doc.Save(getConfigFilePath());}}catch(NullReferenceException e) {throw new Exception(string.Format("The key {0} does not exist.", key), e);}}private static XmlDocument loadConfigDocument(){XmlDocument doc = null;try{doc = new XmlDocument();doc.Load(getConfigFilePath());return doc;}catch (System.IO.FileNotFoundException e){throw new Exception("No configuration file found.", e);}}private static string getConfigFilePath(){return Assembly.GetExecutingAssembly().Location + ".config";}}
}

 

 

http://www.lbrq.cn/news/2689435.html

相关文章:

  • 做家装网站客户来源多吗最好用的磁力搜索器
  • 编程 网站建设如何做一个网站
  • html5在线制作网站模板灰色推广
  • 怀化网站建设联系方式网络运营工作内容
  • 网络营销招聘岗位有哪些推广关键词优化公司
  • 廊坊高端网站制作3小时百度收录新站方法
  • 常见的网站结构有哪些竞价推广sem
  • 限制网站访问ip百度售后客服电话24小时
  • 青州网站建设百度广告一级代理
  • 深圳高端营销网站模板引擎网站
  • 网站定制开发合同营销推广策划
  • index 石家庄网站建设seo网站关键词优化方式
  • 东莞视频网站制作优化大师官网下载
  • 网页qq登陆保护网络seo哈尔滨
  • 政府网站建设团队网页生成器
  • 唐山哪个公司做网站如何在百度上推广业务
  • 汽车展示网站微信拓客的最新方法
  • 鲅鱼圈网站在哪做南京谷歌seo
  • 怎么自己做代刷网站网站快速排名优化报价
  • 小程序搭建是什么意思淘宝seo优化怎么做
  • 镇江方圆建设监理咨询有限公司网站对网络营销的认识
  • wordpress 目录权限管理指定关键词排名优化
  • 当地政府网站建设问卷调查自己做一个网站需要什么
  • 二级域名网站建设百度竞价代运营托管
  • 免费帮助建站营销网络是啥意思
  • 佛山网站设计建设网络营销策略概念
  • 网站快速收录软件云搜索网页版入口
  • 做网站帮外国人淘宝crm系统网站
  • 网站推广公司兴田德润在哪里上海最新疫情
  • 做网站服务器和域名2022黄页全国各行业
  • 【H5】禁止IOS、安卓端长按的一些默认操作
  • 自动驾驶 HIL 测试:构建 “以假乱真” 的实时数据注入系统
  • 游戏中角色持枪:玩家操控角色,角色转向时枪也要转向
  • [激光原理与应用-256]:理论 - 几何光学 - CMOS与CCD传感器成像原理比较
  • 【vue(二)Vuex】
  • 未来物联网大模型:物联网硬件+底层驱动+AI 自动生成和调优LUA脚本,