我正在尝试在方法中显示当前正在复制的文件。
这是代码:
public static void CopyAll(DirectoryInfo source, DirectoryInfo target)
{
// Check if the target directory exists, if not, create it.
if (Directory.Exists(target.FullName) == false)
Directory.CreateDirectory(target.FullName);
// Copy each file into it’s new directory.
foreach (FileInfo fi in source.GetFiles())
{
//Line where the error is
lblBackupStatus.Text = "Copying " + target.FullName.ToString() + fi.Name.ToString();
fi.CopyTo(Path.Combine(target.ToString(), fi.Name), true);
}
// Copy each subdirectory using recursion.
foreach (DirectoryInfo diSourceSubDir in source.GetDirectories())
{
DirectoryInfo nextTargetSubDir = target.CreateSubdirectory(diSourceSubDir.Name);
CopyAll(diSourceSubDir, nextTargetSubDir);
}
}
我得到的错误是:
非静态字段、方法或属性需要对象引用
关于从静态方法调用非静态属性的一些事情,但我不知道如何修复它。
任何帮助表示赞赏!, 谢谢