2017-04-21 1 views
1

에 내 응용 프로그램을 구성하는 데 필요한 새로운 파일을 제공 할 일 하 러 - 여기가 settings.json이다 : 나는 파일의 정확한 경로를 얻는 방법 enter image description here정적 파일의 파일 경로가 로컬 및 서버

?

내가 시도 :

System.Reflection.Assembly.GetExecutingAssembly().Location // gets a DLL somewhere /Temporary ASP.NET Files/ 

을하지만 난 고객 서버에 게시 할 때 위치는이 같은 Web.config의 옆에 (이고 다른 경로) :

enter image description here

아이디어가 있으십니까?

답변

2

AppDomain.CurrentDomain.BaseDirectory을 사용하여 응용 프로그램의 기본 디렉토리를 얻을 수 있습니다. 이 같은

뭔가 작동합니다 : 당신은이 두 가지 방법 중 하나를 시도 할 수 있습니다

string settingsJson = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "settings.json"); 
+0

간단하고 작동합니다. –

1

:

string path = System.IO.Directory.GetCurrentDirectory(); 
string path = Environment.CurrentDirectory; 
Path.Combine(path, "settings.json"); 
관련 문제