【发布时间】: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