我正在尝试检查是否存在xml配置文件。
该文件的名称为MyApp.exe.config
我正在使用
public static bool FileExistsCheck(string filename, string filepath = "")
{
if (filepath.Length == 0)
filepath = Directory.GetCurrentDirectory();
return File.Exists(filepath + "\\" + filename);
}这将返回false,尽管该文件已存在
有没有人能建议检查这个文件是否存在的正确方法?
发布于 2012-10-11 19:53:28
试一试
return File.Exists(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile)msdn
发布于 2012-10-11 19:53:25
在运行时,Directory.GetCurrentDirectory()将返回debug/release/bin目录路径。配置XML文件是否驻留在这些文件夹中?
发布于 2012-10-11 19:54:46
您可以只检查File.Exists(CONFIGFILENAME)。因为.net采用当前目录中的相对路径
https://stackoverflow.com/questions/12838850
复制相似问题