[C#] 실행경로, 시작경로, 현제경로

seung-jae hwang·2019년 3월 28일
0

CSharpUP

목록 보기
3/3
  1. Application.StartupPath
  • 현재 application이 존재하는 경로
  • winform 인 경우에만 사용가능
  • 레지스트리 관계없이 실제 실행 파일
  • Application.ExcutablePath 와 동일
  • string filePath = Application.StartupPaht + @"\testFile.txt";
  1. System.Environment.CurrentDirectory
  • 현재 작업 실행되는 경로
  • winform 이외의 개발 환경에서도 사용가능
  • winform 에서는 "C:\Windows\System32" 경로가 나옴 ( svchost.exe 를 통해 서비스가 등록 되기 때문 )
  • System.IO.Directory.GetCurrentDirectory() 와 동일

[winform의 경우]
1) Application.StartupPath 를 사용
2) string path = System.Reflection.Assembly.GetExecutingAssembly().Location;
path = System.IO.Path.GetDirectoryName(path);
3. AppDomain.CurrentDomain.BaseDirectory

Another one : https://alias007.tistory.com/338

-- Web
1. HttpContext.Current.Request.PhysicalApplicationPath
AppDomain.CurrentDomain.SetupInformation.PrivateBinPath
AppDomain.CurrentDomain.BaseDirectory

  1. System.Web.UI;
    Page.Server.MapPath("./test.text");
    결과 값 : c:\inetpub/test.text 실제경로 반환

-- Win
using System.IO;
string strPath = Path.Combine(path.GetDirectoryName(Application.ExecutablePath), "파일명.확장자");

0개의 댓글