2012-10-06 1 views
3

좋아, Framework 4.0에서 Winform 프로젝트 중 일부를 Framework 4.5로 옮기고 클래스 라이브러리에서 실행 파일 경로를 찾으려고 할 때 문제가 발생합니다. 당신이 볼 수있는Application Path 얻기

using System; 
using System.IO; 
using System.Windows.Forms; 

namespace FunctionClassLibrary 
{ 
    public static class ErrorLogging 
    { 
     public static string errLogFullPath 
     { 
      get 
      { 
       string errLogFile = "Application"; 
       m_errLogFullPath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), errLogFile + "_ErrorLog.txt"); 
       return m_errLogFullPath; 
      } 
     } 
    } 
} 

내가 다시 응용 프로그램을 노출하는 항상 System.Windows.Forms 네임 스페이스를 참조 할 수 있어요 : 내가 여기에 오류를 기록하는 데 사용하는 에러 로깅 클래스 내 코드의 조각입니다 있습니다. ExecutablePath 속성 분명히 Framework 4.5에서 더 이상 System.Windows.Forms 네임 스페이스를 참조 할 수 없습니다. 나는이 아침에 아무런 성공도 거두지 않고있다.이 두 MSDN 링크는 LINK1LINK2 모두 System.Windows.Forms 네임 스페이스를 사용하는 예제를 보여준다. 그래서 내 질문은 누구나이 문제에 대한 해결 방법이 있습니까?

** 업데이트 **

좋아, 내가 내 마음을 잃고 있어요, 난 그냥 단순히 어쨌든이 파일을 저장해야하는 위치 인의 COMMONPROGRAMFILES 폴더를 찾기 위해 Environment.GetFolderPath 방법을 사용할 수 있습니다 실현 . 오늘 아침에 모두들 귀찮게해서 미안해.

답변

5

대신 Directory.GetCurrentDirectory() 또는 AppDomain.CurrentDomain.BaseDirectory를 사용할 수 있습니다

Path.Combine(Directory.GetCurrentDirectory(), 
       errLogFile + "_ErrorLog.txt"); 

또는를 :

Path.Combine(AppDomain.CurrentDomain.BaseDirectory, 
       errLogFile + "_ErrorLog.txt"); 
+0

감사합니다! 이것은 나를 위해 너무 작동합니다. –

2
Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location),errLogFile + "_ErrorLog.txt"); 
+0

정말 고마워요! –