본문 바로가기
프로그래밍/C#, WPF, .Net

[C#, WPF] 자기 자신의(실행 중인 프로그램)의 실행 경로 가져오는 방법 (실행 위치)

by GhostWeb 2021. 3. 6.
반응형

 

* 코드 - 자기 자신(실행 중인 프로그램)의 실행 중인 경로 가져오기

string path = System.Reflection.Assembly.GetExecutingAssembly().Location;
Debug.WriteLine(path);  // 현재 실행중인 프로그램 명을 포함한 경로

path = System.IO.Path.GetDirectoryName(path);
Debug.WriteLine(path);   // 현재 실행중인 프로그램의 경로

 

* 실행 결과

D:\Test\WPF\WPF\bin\Debug\WPF_TEST.exe
D:\Test\WPF\WPF\bin\Debug

 

System.Reflection.Assembly.GetExecutingAssembly().Location; 는 현재 이 코드를 실행한 exe 파일과 확장명을 포함하여 출력하여 경로만 필요하신 분은 System.IO.Path.GetDirectoryName();를 이용하시면 됩니다.

 

반응형