2010-03-25 2 views
4

내 C# winform 응용 프로그램에서 아래 줄을 사용합니다.이 기능은 훌륭하지만 때로는 프로그램이 명령 줄에서 실행될 때 config.xml 파일을 찾을 수 없다는 오류가 발생합니다. 이것은 'working directory'가 다르므로 (필자가 생각하기에) "현재 디렉토리에서 config.xml로드"라고 말할 필요가 있습니다. 어떻게해야합니까? 부하 현재 디렉토리C# 현재 디렉터리에서 xml 파일로드?

Path = System.Web.HttpContext.Current.Server.MapPath(Filename); 

에서

docXML.Load("config.xml"); 

감사 조나단 로딩

답변

7
string fileName = Path.Combine(Application.StartupPath, "config.xml"); 
+0

많은 감사를드립니다. –

3
string Path = ""; 
    string Filename = ConfigurationManager.AppSettings("Filename"); 

베이스 디렉토리에서부터

Path = AppDomain.CurrentDomain.BaseDirectory + Filename;