2013-09-02 5 views
3

서버에서 로컬 시스템으로 파일을 복사하는 중 "경로의 일부를 찾을 수 없습니다"라는 오류가 발생합니다. 다음은 내 코드 샘플입니다.경로의 일부를 찾을 수 없습니다.

try 
      { 
       string serverfile = @"E:\installer.msi"; 
       string localFile = Path.GetTempPath(); 
       FileInfo fileInfo = new FileInfo(serverfile); 
       fileInfo.CopyTo(localFile); 
       return true; 
      } 
      catch (Exception ex) 
      { 
       return false; 

      } 

누구든지 내 코드에 어떤 문제가 있는지 말해 줄 수 있습니까?

답변

5
Path.GetTempPath 

은 경로 경로를 반환합니다. 파일 경로도 지정해야합니다. 당신은 당신이 디렉토리에 제출하지,을 제기 파일을 복사해야이

string tempPath = Path.GetTempPath(); 
string serverfile = @"E:\installer.msi"; 
string path = Path.Combine(tempPath, Path.GetFileName(serverfile)); 
File.Copy(serverfile, path); //you can use the overload to specify do you want to overwrite or not 
+0

감사합니다 ...이 – Abhash786

+0

다행이 일을 지금 일하고있어. – Ehsan

3

처럼 작업을 수행 할 수 있습니다

... 
    string serverfile = @"E:\installer.msi"; 
    string localFile = Path.GetTempPath(); 
    FileInfo fileInfo = new FileInfo(serverfile); 

    // Copy to localFile (which is TempPath) + installer.msi 
    fileInfo.CopyTo(Path.Combine(localFile, Path.GetFileName(serverfile))); 
... 
+0

고마워요 ... 지금 작동 중입니다. – Abhash786

관련 문제