C#程序开机启动时无法读取自定义的配置文件

winform(C#)程序启动时读取自定义的配置文件(xxx.json),手动打开没问题,但是程序随操作系统开机启动时则无法读取文件。

解决的办法:把需要在开机启动时读取的项目放在App.config文件中。

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  
  <appSettings>
    <add key="mode" value="BSAUTO" />
  </appSettings>

</configuration>

引用 System.Configuration

读取配置项:mode

using System.Configuration;

string mode = ConfigurationManager.AppSettings["mode"];
//...

猜你喜欢

转载自blog.csdn.net/zhouyingge1104/article/details/88389116