Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#不复制快照文件_C#_Copy_Shortcut_File Copying - Fatal编程技术网

C#不复制快照文件

C#不复制快照文件,c#,copy,shortcut,file-copying,C#,Copy,Shortcut,File Copying,我使用的是c#,我可以复制我想要的所有类型的文件,但当我想要复制快捷方式或链接文件时,c#错误如下: 这是我的代码: private void button1_Click(object sender, EventArgs e) { string fileName = "HonarVaMemar.exe"; string sourcePath = @Application.StartupPath; string targetPath = @Environment.GetF

我使用的是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);}
将复制所有其他文件


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

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

或者

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


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

直到您不发布stacktrace或
innerException
很难回答到底发生了什么。我有一些猜测

            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);
如果该快捷方式指向其他文件(目标属性),则在复制该快捷方式文件时,目标文件可能未预设在该位置

或者

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

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

单击“详细信息”可能会显示有价值的信息单击“详细信息”可能会显示有价值的信息
            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);