2010-02-10 9 views
0

서버의 디렉토리에있는 파일을 삭제하고 싶습니다. 다음 코드를 시도했지만 file.exist 내부의 코드는 실행되지 않습니다. 항상 파일을 건너 뛰고 그 파일이 존재하지 않습니다. 하지만 파일이 있습니다. 나를 도와주세요. 사전서버에서 삭제할 파일의 경로를 얻는 방법

string filename = "Template\\copy.jpg"; 
     if(System.IO.File.Exists(filename)) 
     { 
      System.IO.File.Delete(filename); 
     } 

답변

2

에 고맙습니다

string fileName = Server.MapPath(@"/Template/copy.jpg"); 
+0

감사합니다. – pankaj

2

당신은 경로를 얻을 수 Server.MapPath를 사용하십시오. 예 :

string filename = Server.MapPath("~/Template/copy.jpg"); 
System.IO.File.Delete(filename); 
+0

Server.MapPath에 전달하기 전에 "~ /"경로에서 ResolveUrl을 호출해야 할 수 있습니다. –

관련 문제