Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

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

Edit: Did I misinterpret the IsPresent Property?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
332 views
Welcome To Ask or Share your Answers For Others

1 Answer

The AppDomain reports on where it expects the configuration file for the application to reside. You can test if the file actually exists (with no need for dummy AppSettings, and no need to try and work out what the configuration file should be called, or where it is located):

public static bool CheckConfigFileIsPresent()
{
   return File.Exists(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...