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 diff开发者_如何学编程erent 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.
精彩评论