如何确定app.config文件是否存在 [英] how to determine whether app.config file exists

查看:585
本文介绍了如何确定app.config文件是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法找出一个app.config文件是否存在,而不使用File.Exists?
我试过

Is there a way to find out whether an app.config file exists, without using "File.Exists"? I tried

if ( !ConfigurationManager.ConnectionStrings.ElementInformation.IsPresent )
{...}

但IsPresent是即便用的app.config连接字符串中存在错误的。

but IsPresent is false even if app.config with a connection string exists.

编辑:
难道我曲解IsPresent地产

Did I misinterpret the IsPresent Property?

推荐答案

最简单的方法我能想到的是添加一些虚拟应用程序设置标志,然后检查该标志,例如:

Most simple way that I can think of is to add some "dummy" application setting flag then check for that flag, e.g.:

if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["dummyflag"]))
{
  //config file doesn't exist..
}

这篇关于如何确定app.config文件是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆