2015-07-11 36 views
1

我使用C#和我可以複製所有類型的我想要的文件,但是當我想警察快捷方式或鏈接文件c#象這樣的錯誤:C#確實沒有複製shotcut文件

enter image description here

這是我的代碼:

private void button1_Click(object sender, EventArgs e) 
{ 
    string fileName = "HonarVaMemar.exe"; 
    string sourcePath = @Application.StartupPath; 
    string targetPath = @Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\Output HonamrvaMemar Version"; 

    // Use Path class to manipulate file and directory paths. 
    string sourceFile = System.IO.Path.Combine(sourcePath, fileName); 
    string destFile = System.IO.Path.Combine(targetPath, fileName); 

    // To copy a folder's contents to a new location: 
    // Create a new target folder, if necessary. 
    if (!System.IO.Directory.Exists(targetPath)) 
    { 
     System.IO.Directory.CreateDirectory(targetPath); 
    } 
    System.IO.File.Copy(sourceFile, destFile, true); 


    //----------------------------------------------------------- 
    string fileName2 = "HonarVaMemar.exe.lnk"; 
    string sourceFile2 = System.IO.Path.Combine(sourcePath, fileName2); 
    string destFile2 = System.IO.Path.Combine(targetPath, fileName2); 
    System.IO.File.Copy(sourceFile2, destFile2, true);} 

其他所有文件都複製

.....

+3

點擊「詳細信息」可能會顯示值得信息 – Plutonix

回答

0

,直到你不發佈堆棧跟蹤或innerException,很難回答到底發生了什麼。我有一些猜測

如果該快捷方式指向某個其他文件(目標屬性),則複製該快捷方式文件時可能是目標文件不在該位置預設。

或..

快捷方式文件可能與其他進程一起使用。

這只是一個猜測,請發佈異常的文本,你會得到複製。

0
  string fileName = "data.mdb"; 

      string sourcePath = @Application.StartupPath; 
      string targetPath = @"C:\Windows\cat"; 

      string sourceFile = System.IO.Path.Combine(sourcePath, fileName); 
      string destFile = System.IO.Path.Combine(targetPath, fileName); 

      // To copy a folder's contents to a new location: 
      // Create a new target folder, if necessary. 
      //if (!System.IO.Directory.Exists(targetPath)) 
      //{ 
      // System.IO.Directory.CreateDirectory(targetPath); 
      //} 

      // To copy a file to another location and 

      System.IO.File.Copy(sourceFile, destFile, true);