【问题标题】:C# does no copy shotcut fileC# 不复制快照文件
【发布时间】:2015-09-30 06:20:38
【问题描述】:

我正在使用 c#,我可以复制我想要的所有类型的文件,但是当我想要复制快捷方式或链接文件时,c# 错误如下:

这是我的代码:

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);}

复制所有其他文件

.....

【问题讨论】:

  • 点击“详细信息”可能会显示有价值的信息

标签: c# copy shortcut file-copying


【解决方案1】:

除非您不发布堆栈跟踪或innerException,否则很难回答到底发生了什么。我有一些猜测

如果该快捷方式指向某个其他文件(Target 属性),则在复制该快捷方式文件时,目标文件可能未预设在该位置。

或者..

可能快捷方式文件正在与其他进程一起使用。

这只是一个猜测,请发布您在复制时遇到的异常文本。

【讨论】:

    【解决方案2】:
                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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-29
      • 2017-06-25
      • 2021-01-10
      相关资源
      最近更新 更多