简体   繁体   中英

how to check whether a .config file exist or not in a folder C#?

I want to read a.config file. Before I read the file I need to make sure whether the file is in the folder or not. At the moment i am using a System.Configuration.AppSettingsReader to read the configuration file it only reads when the file is in the folder as soon as i moved the file in different folder i throws me a error. But i don't know how to check whether there is a.config file in a folder or not. What i want to do is if the.config is in the folder get reader.getvalue and perform some action and if the.config file is not in the folder do something else. Is ther any way of checking just the extension of the particular file in C#?

thanks

Just use simple System.IO.File.Exists(path) method to check the file exists in the c. Here is MSDN article

Just catch the ConfigurationErrorsException and go from there, or you can check the filesystem for the filename to see if the file actually exists.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM