if (!System.IO.Directory.Exists(filetarget))
{
  System.IO.Directory.CreateDirectory(filetarget);
}
System.IO.File.Copy(sourceFile, destFile, true);
最后的System.IO.File.Copy(sourceFile, destFile, true);只能在第一次复制时候成功,第二次为什么就卡住不动了?

解决方案 »

  1.   

    http://zhidao.baidu.com/question/201951683.html
      

  2.   

     If System.IO.File.Exists(FileName) ' 使用 System.IO.File.Exists 判斷是否存在
            System.IO.File.Copy(FileNameSource, FileName, True) ' 使用 System.IO.File.Copy 複製檔案,第三個參數 True 表示覆蓋檔案
      

  3.   

    先把思路理顺了 判断一下有没有同名文件 如果有的话 执行你最后一段代码 如果没有的话 就直接用System.IO.File.Copy(sourceFile, destFile);看看还会有什么问题,如果实在不行 确实想覆盖,那就把之前的文件用代码删除掉再执行复制。。
      

  4.   


    if(!System.IO.Directory.Exists(@"C:\text")) 

    // 目录不存在,建立目录 
    System.IO.Directory.CreateDirectory(@"C:\text"); 

    String sourcePath = "c:\\源文件目录\\原文件名称.txt"; 
    String targetPath = "d:\\目标文件目录\\新的文件名称.aspx"; 
    bool isrewrite=true; // true=覆盖已存在的同名文件,false则反之 
    System.IO.File.Copy(sourcePath, targetPath, isrewrite); 
    希望对你有帮助 我暂时没时间细帮你弄