2013-02-28 3 views
2

MVC4 응용 프로그램이 있는데 하나의 제어기 메소드가 일부 파일 (이 파일에는 몇 가지 Json 객체가 있음)을 가져 와서 proccessit, deleteit을 읽습니다.파일의 상대 경로 얻기 asp.net

해당 파일은 ftp를 사용하여 내 사이트에 업로드됩니다. 내 프로젝트 구조가 이렇게 sometrhing입니다

wwwroot 
    bin 
    content 
    images 
    scripts 
    suscribers // This is my ftp folder 
    _suscriber1 
     _proccess1 
     file1.txt //This is a Json file 
     file2.txt 
     ... 
     _proccess2 
     ... 
    _suscriber2 
    ... 

내 모든 파일 (file1.txt ...)이로드되었습니다. 내 컨트롤러에서, 나는이 방법으로 file1.txt를 읽으려고한다.

string suscriberDir= string.Format("_{0}", suscriber.Id); 
string[] laPath = {System.AppDomain.CurrentDomain.BaseDirectory, "suscribers", suscriberDir}; 
string lcPath = Path.Combine(laPath); 
string[] laPath2 = { lcPath, "_proccess1" , "_File1.txt" }; 
lcPath = Path.Combine(laPath2); 
StreamReader reader = new StreamReader(lcPath); 
string personas = reader.ReadToEnd(); 
reader.Close(); 

내 문제는 필자에게 filenotfound 예외를 던지고 있다는 것이다.

file1.txt를 읽고 내용을 얻는 올바른 방법은 무엇입니까?

+1

이 코드를 디버깅 했습니까? "CurrentDomain.BaseDirectory"는 "bin \ Debug"폴더라고 생각합니다. 당신은 거기에 중단 점을 던져 시도하고 오래된 패션 디버깅을 할 –

+0

그래, 내가 그것을 디버깅 해요 .. "옛 패션" –

답변

7

사용 시도 Server.MapPath("_File1.txt");

+1

_File1.txt 여러 dirs 존재할 수 있습니다 ..이 방법은 무엇입니까? –

+1

예, 당신이 옳았습니다. 제 컨트롤러가 bin dir에 있습니다. 내 마지막 솔루션'Server.MapPath ("../ suscribers/_suscriber1/_process1/File1.txt")'. –