2012-10-11 2 views
0

xml 구성 파일이 있는지 확인하려고합니다.xml 구성 파일 찾기

파일은 내가

public static bool FileExistsCheck(string filename, string filepath = "") 
{ 
    if (filepath.Length == 0) 
     filepath = Directory.GetCurrentDirectory(); 
    return File.Exists(filepath + "\\" + filename); 
} 

사람이 있는지 확인하는 올바른 방법에 대한 조언을 할 수있는 기존 파일에도 불구하고 false을 반환을 사용하고있는 이름 MyApp.exe.config

있다 이 파일이 존재하지 않습니까?

+0

http://stackoverflow.com/questions/837488/how-can-i- 응용 프로그램 경로에서 실행중인 콘솔 앱에서 – bryanmac

+0

http://stackoverflow.com/questions/295687/get-path-to-execution-directory-of-windows-forms-application – bryanmac

+0

왜 알 필요가 있니? 아마도 당신이 원하는 것을 성취 할 수있는 또 다른 방법이있을 것입니다. –

답변

2

당신은 단지 File.Exists (하고 configfilename)를 확인할 수 있습니다

return File.Exists(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile) 

msdn

0

런타임에 Directory.GetCurrentDirectory()은 debug/release/bin 디렉토리 경로를 반환합니다. 구성 XML 파일이 해당 폴더에 있습니까?

0

을 시도합니다. .net 현재 경로에서 relativ 경로를 사용하기 때문에

0

처음에는 Path.Combine(path, fileName);을 사용하여 경로를 만드는 것이 좋습니다.

두 번째 사용 Application.StartupPath의 경우 Directory.GetCurrentDirectory이 아님.

세 번째로, 응용 프로그램 폴더에 MyApp.exe.config이 포함되어 있는지 확인하십시오.

0

이 방법을 고려하시기 바랍니다 :

public static bool isFileExist(string filePath) 
{ 
    if (File.Exists(filePath)) 
     return true; 
    else return false; 
} 

을 나는 당신의 방법에 범인이 생각 :

filepath = Directory.GetCurrentDirectory();