1. /// <summary>
  2. /// 处理xml文件
  3. /// </summary>
  4. public class HandelXmlFile
  5. {
  6. private string _configPath;
  7. ///文件地址
  8. private void SetPath<T>()
  9. {
  10. var type = typeof(T);
  11. _configPath = AppDomain.CurrentDomain.BaseDirectory + @"Config\" + type.Name + ".config";
  12. if (!File.Exists(_configPath))
  13. File.Create(_configPath);
  14. }
  15. /// <summary>
  16. /// 保存xml文件
  17. /// </summary>
  18. public void Save<T>(T model)
  19. {
  20. try
  21. {
  22. SetPath<T>();
  23. using (FileStream fs = new FileStream(_configPath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite))
  24. {
  25. XmlSerializerHelper.Serialize(fs, model);
  26. }
  27. }
  28. catch { }
  29. }
  30.  
  31. public T OpenFiles<T>()
  32. {
  33. try
  34. {
  35. SetPath<T>();
  36. if (File.Exists(_configPath))
  37. {
  38. using (FileStream fs = new FileStream(_configPath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
  39. {
  40. return XmlSerializerHelper.DeSerialize<T>(fs);
  41. }
  42. }
  43. return default(T);
  44. }
  45. catch { return default(T); }
  46. }
  47. }

c#本地文件配置xml的更多相关文章

  1. axios获取本地文件配置步骤

    首先修改一下config文件夹下面的index.js文件里面的配置,如下: 然后 ,通过axios 请求配置的接口 <script> import axios from 'axios' e ...

  2. Java-JDBC.mysql 工具类 读取本地文件配置

    引用 mysql-connector-jav 的jar 配置文件为  database.propertties .  格式如下 driverClass=com.mysql.jdbc.Driver ur ...

  3. 使用WWW获取本地文件夹的XML配置文件

    Unity3D读取本地文件可以使用Resources.Load来读取放在Resources文件夹下的文件,如果不是放在该文件夹下,则可以通过WWW类来读取. 譬如读取xml的配置文件. /// < ...

  4. web.xml 文件配置01

    web.xml 文件配置01   前言:一般的web工程中都会用到web.xml,方便开发web工程.web.xml主要用来配置Filter.Listener.Servlet等.但是要说明的是web. ...

  5. tomcat中的server.xml文件配置了URIEncoding="UTF-8"需要注意的问题

    1.      get请求传递中文时本地连正式库访问都正常,正式环境下单独访问报错 代码: 请求:project/projectInfo/export/?cks=’项目类型 public String ...

  6. mybatis-config.xml核心文件配置

    一.全局配置文件结构 configuration 配置 properties 属性:可以加载properties配置文件的信息 settings 设置:可以设置mybatis的全局属性 typeAli ...

  7. Tomcat下conf下server.xml的文件配置信息

    Tomcat下conf下server.xml的文件配置信息,基本上不用做任何修改就可以使用,修改的地方就是host区域的一些配置,此文件设置端口为80. 注意:Tomcat配置文件中(即server. ...

  8. Android通过xml文件配置数据库

    之前一段时间自己封装了两个数据库,一个是ORM数据库,另一个是事件流数据库,项目相应的地址如下: ORM数据库:https://github.com/wenjiang/SimpleAndroidORM ...

  9. 在MFC程序中使用XML文件配置工具栏

    现在我发现使用Visual Studio的资源编辑器进行编辑资源有着诸多的不便:首先是任何资源的变动一般变动代码,不利于系统维护,其次Visual Studio的资源编辑器的本身的功能有限,也不利于界 ...

随机推荐

  1. maven打包遇到错误,Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.1:test

    对Pom文件进行配置(亲自尝试,已成功解决) <build> <plugins> <plugin> <groupId>org.apache.maven. ...

  2. [go]template使用

    //index.html {{if gt .Age 18}} <p>hello, old man, {{.Name}}</p> {{else}} <p>hello, ...

  3. windows下使用eclipse远程编写hadoop配置

    1.按照一般方法配置好hadoop伪分布式,注意core-site.xml和mapred-site.xml用IP,不要用localhost 2.格式化hdfs文件系统hadoop namenode - ...

  4. C++ replace replace_if replace_copy replace_copy_if

    #include <iostream>#include <list>#include <algorithm>#include <iterator>#in ...

  5. python3 __mian和__name__的区别

    1.新建 test.py 模块: def GetModuleName(): print('__name__ = ', __name__) def PrintName(): print('PrintNa ...

  6. ThreadLocal的简单介绍

    ThreadLocal是什么 早在JDK 1.2的版本中就提供java.lang.ThreadLocal,ThreadLocal为解决多线程程序的并发问题提供了一种新的思路.使用这个工具类可以很简洁地 ...

  7. Semaphore 并发信号

    package com.thread; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executo ...

  8. [Tensorflow] 使用 model.save_weights() 保存 / 加载 Keras Subclassed Model

    在 parameters.py 中,定义了各类参数. # training data directory TRAINING_DATA_DIR = './data/' # checkpoint dire ...

  9. 【转】TCP/IP网络协议各层首部

    ​ 数据包封装流程(逐层封装,逐层解封) 二层帧(二层帧中目的地址6个字节,源地址6个字节,长度/类型2个字节,二层帧共18个字节) ip头部(ip头部20字节) tcp头部(tcp头部20个字节): ...

  10. Linux selinux 防火墙

    cat /etc/selinux/config # This file controls the state of SELinux on the system. # SELINUX= can take ...