2012-04-09 2 views
0

이상한 문제가 있습니다. 업로드 된 파일을 데이터베이스에 저장 한 다음 업로드 된 파일 을 업로드 폴더에서 삭제하려고합니다.File.Delete()는 실행 모드에서는 작동하지 않지만 디버그 모드에서만 작동합니다.

디버그 모드에서 제대로 작동하지만 실행 모드에서 파일은 삭제되지 않은 상태로 유지됩니다.

누구든지이 문제에 직면 했습니까?

이 아래 4

코드 .NET에게 있습니다 : IMO

private string SaveFiles(string rootFolder) 
{ 
    var uploadedPhotos = GetAllFilesUploaded(); 
foreach (var file in uploadedFiles) 
{ 
       string path= Path.Combine(rootFolder, "userfile", file.FileName); 

       FileService.SaveUploadedFile(fileName, GetBytesFromLocalFile(path)); 

       File.Delete(path); <-- this only works in debug mode!! 

       } 
    } 

    public static byte[] GetBytesFromLocalFile(string filePath) 
      { 
       using (FileStream fs = new FileStream(filePath, FileMode.Open)) 
       { 
        byte[] bytes = new byte[fs.Length]; 
        fs.Read(bytes, 0, (int)fs.Length); 
        return bytes; 
       } 
      } 
+0

동일한 문제가 있습니다. 이걸 해결 했니? 내 대답은 – Jelling

답변

2

는 디버그 모드에서 작동되기 때문에 다음이 더 코딩 문제가 없습니다. File.Delete (경로)에 제공되는 경로에 문제가 있습니다. 릴리스 모드에서 확인 경로

If the file to be deleted does not exist, no exception is thrown. 

http://msdn.microsoft.com/en-us/library/system.io.file.delete.aspx에 ACC입니다. bin 폴더의 Release and Debug Folder와 관련이 있습니다.

2

Nikhil의 답을 덧붙이려면 path이있는 MessageBox을 릴리스 모드로 설정하고 경로가 올바른지 수동으로 확인하십시오.

참고 : 이후 MessageBox을 반드시 삭제해야합니다.

+0

+1입니다. –

관련 문제